optimization - How to model this hash with values as list in redis? -


i have store data in redis, data stored of form

{   "key" : {         "k1":["v1", "v2", "v3"],         "k2":["v4", "v5"],         "k3":["v1", "v2]}     },   "key1" :{         "k1":["v11", "v2"],         "k2":["v4", "v15", "v3"],         "k3":["v12", "v2]}     } } 

according documentation, can not have list value in hash data structure. best way modelling this, list generated 1 value @ time, need append or add. should there different database each of top level keys?, or should there different instances of redis needs brought top level keys used identify specific database or instance in mid level key can used key load values in list or set?

redis quite flexible regarding how can structure data, here possible approach.

since hash values have strings, can keys referring lists. can create list of values under top-level key:

redis> lpush list_value:k1 v1 (integer) 1 redis> lpush list_value:k1 v2 (integer) 2 redis> lpush list_value:k1 v3 (integer) 3 

then set key referring list value of hash:

redis> hset key k1 list_value:k1 (integer) 1 

to fetch list of values, first key values stored:

redis> hget key k1 "list_value:k1" 

then use key retrieve list of values:

redis> lrange list_value:k1 0 -1 1) "v3" 2) "v2" 3) "v1" 

you should use namespaces (typically based on colon separators) name keys pointing lists of values in order avoid clashes keys of hashes.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -