Most efficient way to get several hashes in Redis?

前端 未结 1 1904
长情又很酷
长情又很酷 2021-01-01 11:59

So I\'ve already read this post about there not being an MGET analog for Redis hashes. One of the answers said to use MULTI/EXEC to do the operatio

相关标签:
1条回答
  • 2021-01-01 12:57

    The most efficient way would be using a pipeline.

    Assuming you want everything for a given key and know all the keys already:

    import redis
    
    r = redis.Redis(host='localhost', port=6379, db=0)
    p = r.pipeline()
    for key in keys:
        p.hgetall(key)
    
    for h in p.execute():
        print h
    

    More information about pipelines can be found here: http://redis.io/topics/pipelining

    0 讨论(0)
提交回复
热议问题