使用PYTHON实现一个redis工具类
时间: 2023-01-15 22:14:01 浏览: 119
好的,下面是一个使用 Python 实现的 Redis 工具类的例子:
```
import redis
class RedisClient:
def __init__(self, host='localhost', port=6379, db=0):
self.redis = redis.Redis(host=host, port=port, db=db)
def set(self, key, value):
self.redis.set(key, value)
def get(self, key):
return self.redis.get(key)
def delete(self, key):
self.redis.delete(key)
def incr(self, key):
self.redis.incr(key)
def decr(self, key):
self.redis.decr(key)
def hset(self, name, key, value):
self.redis.hset(name, key, value)
def hget(self, name, key):
return self.redis.hget(name, key)
def hgetall(self, name):
return self.redis.hgetall(name)
def hdel(self, name, key):
self.redis.hdel(name, key)
def lpush(self, name, *values):
self.redis.lpush(name, *values)
def rpush(self, name, *values):
self.redis.rpush(name, *values)
def lpop(self, name):
return self.redis.lpop(name)
def rpop(self, name):
return self.redis.rpop(name)
def llen(self, name):
return self.redis.llen(name)
def lrange(self, name, start, end):
return self.redis.lrange(name, start, end)
def sadd(self, name, *values):
self.redis.sadd(name, *values)
def srem(self, name, *values):
self.redis.srem(name, *values)
def smembers(self, name):
return self.redis.smembers(name)
def sismember(self, name, value):
return self.redis.sismember(name, value)
def zadd(self, name, *args, **kwargs):
self.redis.zadd(name, *args, **kwargs)
def zrange(self, name, start, end, desc=False, withscores=False):
return self.redis.zrange(name, start, end, desc=desc, withscores=withscores)
def zrem(self, name, *values):
self.redis.zrem(name, *values)
def zcard(self, name):
return self.red
阅读全文