redis pipeline实现,合并多个请求,可有效降低redis访问延迟

上代码

import redis

try:
    pool = redis.ConnectionPool(host=host, port=port)
    r = redis.Redis(connection_pool=pool)
except Exception as e:
    print(f"Failed to connect to {host} with error: {e}")
try:
    pipeline = r.pipeline(transaction=False)  # Use the last Redis connection for the pipeline
    pipeline.get("twotoone_test")
    pipeline.zrevrange("twotoone_test", 0, -1, withscores=True)
    results = pipeline.execute()
    print(results)
except Exception as e:
    print(f"Failed to execute pipeline with error: {e}")

注意,r.pipeline(transaction=False)需要加上该参数,否则可能会有报错:

Err unknown or unsupported command ‘exec

你可能感兴趣的:(redis,bootstrap,前端)