Is there MGET analog for Redis hashes?

前端 未结 5 1905
庸人自扰
庸人自扰 2020-12-13 08:56

I\'m planning to start using hashes insead of regular keys. But I can\'t find any information about multi get for hash-keys in Redis wiki. Is this kind of command is support

5条回答
  •  时光取名叫无心
    2020-12-13 09:18

    You can query hashes or any keys in pipeline, i.e. in one request to your redis instance. Actual implementation depends on your client, but with redis-py it'd look like this:

    pipe = conn.pipeline()
    pipe.hgetall('foo')
    pipe.hgetall('bar')
    pipe.hgetall('zar')
    hash1, hash2, hash3 = pipe.execute()
    

    Client will issue one request with 3 commands. This is the same technique that is used to add multiple values to a set at once.

    Read more at http://redis.io/topics/pipelining

提交回复
热议问题