Redis 哈希是否有 MGET 模拟? [英] Is there MGET analog for Redis hashes?

查看:67
本文介绍了Redis 哈希是否有 MGET 模拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算开始使用哈希代替常规键.但是我在 Redis wiki 中找不到有关哈希键的 multi get 的任何信息.Redis支持这种命令吗?

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 supported by Redis?

谢谢.

推荐答案

您可以查询管道中的哈希或任何键,即在对 redis 实例的一个请求中.实际实现取决于您的客户端,但使用 redis-py 时它看起来像这样:

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

客户端将使用 3 个命令发出一个请求.这与用于一次向集合添加多个值的技术相同.

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.

http://redis.io/topics/pipelining

这篇关于Redis 哈希是否有 MGET 模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆