0

i'm very new to redis. we have a requirement where I need to create a table like structure in redis.

ID | Name | Region | Time
01 | Aaa | s1 | ...
02 | Bbb | s2 | ...

  1. I need to add constraint for Primary Key(ID,Name,Region)
Adarsh r
  • 11
  • 2
  • You probably want a hash https://redis.io/topics/data-types where the key in redis is the primary key you need (you may have to calculate this out side of redis since you want it based on a combination of values) – madebydavid Jan 25 '19 at 14:01

1 Answers1

0

You can create a Hash map storing all the row of the table and key name should be Primary Key. For example

// key should be the primary key
hmset user:1:Aaa:s1 id 1 name Aaa Region s1 Time 12:00
hmset user:2:Bbb:s2 id 2 name Bbb Region s2 Time 11:00

Key name is the primary Key user:1:Aaa:s1.
If you want to retrieve the key with the different name you have to create key and point to this hash.

For example:

// If you want to retrieve with the userId.
set user:1 user:1:Aaa:s1
set user:2 user:2:Bbb:s2
Supermacy
  • 1,429
  • 15
  • 24
  • is there a way to retrieve data by name? – Adarsh r Jan 28 '19 at 11:45
  • Yes there is, as the name is repetitive you have to make the set like **user:Aaa** which contains the hashIds **user:1:Aaa:s1**. The commands is ```sadd user:Aaa:user:1:Aaa:s1``` – Supermacy Jan 28 '19 at 17:36