Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis: How to give an unique id to hashes

Tags:

redis

I want to save my users information in hashes. I want to create a hash for each user in the application. The hashes name is like this: "user:1001"
Now, i want to users id start from 1000 and increase by one.
how can i do this?
thanks

like image 575
Mosayeb Avatar asked Aug 22 '14 13:08

Mosayeb


1 Answers

You can have a key called user:id, which will be a number that you will increment to obtain new ids. In your case, you can set the initial value to 1000:

SET user:id 1000

Then by using INCR you will be able to get a new id for your next user:

INCR user:id

Depending on the language you use, there may be already some tools to solve this problem. I would recommend you check Ohm, or one of the ports.

like image 107
soveran Avatar answered Oct 08 '22 04:10

soveran