我想在django-redis中使用Redis管道(执行多个命令)。
我们可以在Redis中使用multi和exec命令,但是如何在django-redis中使用?
的一个解决方案是:
我有散列键列表,我想要使用散列键获取所有散列。
在每个迭代命令中,发送到redis服务器逐个获取散列。
for hashkey in feedlist:
result = con.execute_command('hgetall',hashkey)
print(result)这不是个好主意,相反,我们可以使用redis管道。但是我怎样才能在django-redis实现Redis管道呢?
发布于 2020-03-07 08:45:40
在django-redis中使用Redis管道。
#first create pipline object using con object
pipeline = con.pipeline()将所有命令插入管道。一个一个地获取所有散列键并将它们插入管道中。
if feedlist:
for post in feedlist:
pipeline.execute_command('hgetall',post)
#hgetall redis command to get all items of given hash key然后调用管道上的execute()方法。它将返回结果变量。
result = pipeline.execute()Redis事务
多、执行、丢弃和观察是Redis交易的基础。它们允许在一个步骤中执行一组命令。
优势
也读
https://stackoverflow.com/questions/60446903
复制相似问题