I'm very new to Redis, and looking to see if its possible to do. Imagine I'm receiving data like this:
{ "account": "abc", "name": "Bob", "lname": "Smith" }
{ "account": "abc", "name": "Sam", "lname": "Wilson" }
{ "account": "abc", "name": "Joe"}
And receiving this data for another account:
{ "account": "xyz", "name": "Bob", "lname": "Smith" }
{ "account": "xyz", "name": "Sam", "lname": "Smith"}
I would like to keep this data in Redis in similar format:
abc:name ["Bob", "Sam", "Joe"]
abc:lname ["Smith", "Wilson", Null]
And for xyz:
xyz:name["Bob", "Sam"]
xyz:lname["Smith", "Smith"]
So the question is what data types should I use to store this Redis?
If your goal is to check if
Bob
is used as aname
for the accountabc
the solution should be something like:Sample Data
Do this (using a redis set):
You'll then be able to check if
Bob
is used as aname
for the accountabc
, with:To retrieve all values of a field use SMEMBERS:
Note:
[account]:[field]
format. Where[account]
can beabc
,xyz
and so on andfield
can bename
,lname
...If you don't want unique value, for instance:
abc:name ["Bob", "Sam", "Joe", "Bob", "Joe"]
then you should use a list instead