【问题标题】:RedisCluster MGET with pipeline带管道的 RedisCluster MGET
【发布时间】:2021-08-13 14:51:22
【问题描述】:

我正在尝试使用管道在我的 Redis 上执行 MGET 操作以提高性能。 我曾尝试一次性完成 MGET 以及批处理流程

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()

到目前为止,我得到了错误

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. 如果没有,还有其他库可以用来存档吗?

【问题讨论】:

    标签: python redis pipeline redis-cluster


    【解决方案1】:

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

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多