首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带流水线的RedisCluster MGET

带流水线的RedisCluster MGET
EN

Stack Overflow用户
提问于 2021-05-25 11:02:45
回答 1查看 615关注 0票数 0

为了提高性能,我尝试在Redis上执行MGET操作。我尝试过一次完成MGET,就像批量流一样。

代码语言:javascript
复制
from rediscluster import RedisCluster
ru = RedisCluster(startup_nodes=[{"host": "somecache.aws.com", "port": "7845"}], 
        decode_responses=True, 
        skip_full_coverage_check=True)
    
pipe = ru.pipeline()        
# pipe.mget(keys)
    
for i in range(0, len(keys), batch_size):
    temp_list = keys[i:i + batch_size]
    pipe.mget(temp_list)

resp = pipe.execute()

到目前为止,我得到的是错误

代码语言:javascript
复制
raise RedisClusterException("ERROR: Calling pipelined function {0} is blocked 
when running redis in cluster mode...".format(func.__name__))
rediscluster.exceptions.RedisClusterException: ERROR: 
Calling pipelined function mget is blocked when running redis in cluster mode...

我想知道的是

  1. 有RedisCluster流水线MGET吗?
  2. ,如果没有,还有其他库可以用来存档吗?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-29 03:34:44

原来我们不能使用MGET与管道,下面是m最终的解决方案。

代码语言:javascript
复制
from rediscluster import RedisCluster
    
def redis_multi_get(rc: RedisCluster, keys: list):
    pipe = rc.pipeline()
    [pipe.get(k) for k in keys]
    return pipe.execute()
    
if __name__ == '__main__':
    rc = RedisCluster(startup_nodes=[{"host": host, "port": port}], decode_responses=True, skip_full_coverage_check=True)
    keys = rc.keys(PREFIX + '*')
    cache_hit = redis_multi_get(rc, keys)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67686642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档