0

Is it possible to store data in the following structure in Redis(using Jedis)?

key
 |-fieldA
 |   |-value1
 |   |-value2
 |   |-value3
 |
 |-fieldB
     |-value4
     |-value5
     |-value6

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.