Redis: How to give a unique identifier to hashes

I want to store information about my users in hashes. I want to create a hash for each user in the application. The hash name looks like this: "user: 1001"
Now I want users to start at 1000 and increase by one.
How can i do this?
thanks

+6
source share
1 answer

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

 SET user:id 1000 

Then, using INCR , you can get a new identifier for the following user:

 INCR user:id 

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

+8
source

Source: https://habr.com/ru/post/974216/


All Articles