import redis
import pickle
class RedisQueue():
def __init__(self):
redis_host = "*****"
redis_password = "*****"
redis_db = 7
pool = redis.ConnectionPool(host=redis_host, port=6379, db=redis_db,
password=redis_password) # 构建redis链接池,减少链接redis需要的时间。
self.red = redis.Redis(connection_pool=pool)
# self.red.zincrby()
def get(self, name):
"""
移除redis中值,返回被移除的值。
:rtype: object
"""
get_content = self.red.lpop(name)
return pickle.loads(get_content)
def put(self, name, value):
"""
在redis列表中添加一个或多个值
:rtype: object
"""
self.red.rpush(name, pickle.dumps(value))
def set(self, name, value):
self.red.set(name, value)
if __name__ == '__main__':
s = [105.718441398371, 38.8440431389595, "c812895bb3d834d69c9d68ab"]
r = RedisQueue()
r.put('demo', s)
d = r.get('demo')
print(d)
Redis队列
最新推荐文章于 2022-12-27 16:22:56 发布