写一个php+redis封任何类型的操作redis类
时间: 2023-05-18 14:04:38 浏览: 53
好的,以下是一个可以封装任何类型的操作redis的PHP类:
```
class RedisHelper {
private $redis;
public function __construct($host, $port) {
$this->redis = new Redis();
$this->redis->connect($host, $port);
}
public function set($key, $value) {
$this->redis->set($key, $value);
}
public function get($key) {
return $this->redis->get($key);
}
public function hset($key, $field, $value) {
$this->redis->hset($key, $field, $value);
}
public function hget($key, $field) {
return $this->redis->hget($key, $field);
}
public function lpush($key, $value) {
$this->redis->lpush($key, $value);
}
public function rpop($key) {
return $this->redis->rpop($key);
}
public function zadd($key, $score, $value) {
$this->redis->zadd($key, $score, $value);
}
public function zrange($key, $start, $stop) {
return $this->redis->zrange($key, $start, $stop);
}
}
```
这个类可以进行set、get、hset、hget、lpush、rpop、zadd、zrange等操作,可以封装任何类型的redis操作。