English 中文(简体)
在 Redis 使用嵌套对象吗?
原标题:Working with nested objects in Redis?

说我有一个散沙 在那里,一个巢穴财产 可以改变。

"key1": {
  "prop1": {
    "subprop1": "could_change"
  }
}

如果我被发送到 prop1.subpop1 已更改的信息, 我能否预先更新此属性的原子? 现在 node_redis prop1 保存为显示 [object objects] 的字符串。 如果 I JSON.stringify () the obj, 那么我需要检索对象, 以内存方式分析对象, 编辑, 然后字符串化并保存对象 - 不知道在平均时间是否有变化 。

如果我用不同的方式处理这些数据, 有人可以解释吗? 我有一个可以嵌套属性的物体, 除了需要从整个对象中取回外, 我还需要更新部分属性 。

谢谢你的帮助!

问题回答

卢阿脚本或锁定模式可以解决你的问题

EVAL  local obj = cjson.decode(redis.call("GET", "key1")); obj.prop1.subprop1 = ARGV[1]; redis.call("SET", "key1", cjson.encode(obj));  0 "did_change"

如果你愿意的话,你甚至可以在Lua做一些更先进的东西 来编辑任何关键 的 JSON 子对象。

查看>Redis SETNX 命令 docs ,例如如何使用锁。





相关问题
How do you mix SQL DB vs. Key-Value store (i.e. Redis)

I m reviewing my code and realize I spend a tremendous amount of time taking rows from a database, formatting as XML, AJAX GET to browser, and then converting back into a hashed javascript object ...

Predis sharding (consistent hashing)

Predis claim to have Client-side sharding (support for consistent hashing of keys). http://github.com/nrk/predis I can do sharding using connect to an array of profiles (nodes) but it isn t ...

key value stores for extendable objects

http://www.infoq.com/presentations/newport-evolving-key-value-programming-model is a video about KV stores, and the whole premise is that redis promotes a column-based style for storing the attributes ...

nginx/redis and handling tracking params in url

I am using nginx and redis in my website. For several items on my site, I want to add tracking params to their urls so that when a user clicks on an item, I can collect statistics of user usage apart ...

热门标签