【问题标题】:Hashing a hash in redis在redis中散列哈希
【发布时间】:2021-07-01 10:10:35
【问题描述】:

我一直在阅读我在redis中不能有嵌套数据结构,而包含的唯一方法是创建一个引用 给它。

如果我理解正确,在 redis 中创建 通用结构 的方法是:

hmset ARandomStringAsAKey name kostas address milky_way

我尝试以这种方式存储 哈希

hmset ReferenceTest name kostas ref ARandomStringAsAKey

然后尝试通过以下方式取回它:

hget ReferenceTest ref

但我唯一得到的是一个字符串,上面写着ARandomKeyAsAString

我怎么可能这样做?

提前致谢!

【问题讨论】:

    标签: database redis nosql


    【解决方案1】:

    你无法通过hget ReferenceTest ref 得到你想要的。 你应该:

    1. 通过hget ReferenceTest ref获取密钥
    2. 通过返回值获取真实数据(ARandomKeyAsAString )
    127.0.0.1:6379> hmget ReferenceTest ref
    1) "ARandomStringAsAKey"
    127.0.0.1:6379> hgetall ARandomStringAsAKey
    1) "name"
    2) "kostas"
    3) "address"
    4) "milky_way"
    
    

    顺便说一句:我们不会这样存储数据,我们将name kostas address milky_way转换成一个json字符串,然后存储。

    127.0.0.1:6379> hmset ReferenceTest name kostas data "{\"name\":\"kostas\",\"address\": \"milky_way\"}"
    OK
    127.0.0.1:6379> hget ReferenceTest data
    "{\"name\":\"kostas\",\"address\": \"milky_way\"}"
    127.0.0.1:6379>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-26
      • 2012-12-25
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 2012-10-01
      • 2012-07-02
      相关资源
      最近更新 更多