上代码
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)需要加上该参数,否则可能会有报错: