如何在redis中存储哈希数组
我想在 redis 中存储哈希数组,编码的最佳方法是什么?
I want to store array of hashes in redis , what is best way to code it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想在 redis 中存储哈希数组,编码的最佳方法是什么?
I want to store array of hashes in redis , what is best way to code it ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
AFAIK 的唯一方法是取消引用它们。假设您有一个包含 2 个哈希值的数组,例如:
{foo: 'bar', baz: 'qux'}
。您可以单独存储它们,然后创建一个引用它们的集合:
然后您可以通过查询集合来检索它们:code> 在所有返回的键上重建原始哈希数组。
SMEMBERS myarr
,然后调用HGETALL
HGETALL我希望这是有道理的。如果您找到更聪明的方法,我会很高兴听到。
The only way AFAIK is to de-reference them. Say you have an array of 2 hashes like:
{foo: 'bar', baz: 'qux'}
.You'd store them separately, and then create a SET that references them all:
Then you can retrieve them all by querying the set:
SMEMBERS myarr
and then callHGETALL <key>
on all the returned keys to rebuild your original array of hashes.I hope this makes sense. And if you find a smarter way I'd be happy to hear it.
如果您使用的语言支持 json 转换,则可以将哈希转换为 json 并将其附加到列表中。您可以在 Ruby 中执行以下操作:
If you are using a language which supports to/from json conversion, you can convert your hash to json and append it in a list. You can do the following in Ruby: