Reputation: 4502
Is it possible to store data in the following structure in Redis(using Jedis)?
key
|-fieldA
| |-value1
| |-value2
| |-value3
|
|-fieldB
|-value4
|-value5
|-value6
Upvotes: 0
Views: 528
Reputation: 50726
Redis doesn't technically support the data structure you want. There are a few workarounds; a simple one is to create a separate list for each field, making the redis key a combination of your key and the specific field. For example:
LPUSH key:fieldA value1 value2 value3
LPUSH key:fieldB value4 value5 value6
Another approach is to use a hash, with a serialized form for your values:
HSET key fieldA "value1,value2,value3"
HSET key fieldB "value4,value5,value6"
This makes it less convenient to add and remove individual values, but provides the additional functionality of a unified hash.
Upvotes: 2