Reputation: 27
I just started Redis. I need to create a database for online store or whatever. Main idea to show functionality. I never worked in Redis and terminal, so a bit confusing. Firstly I want to create a database of users with id users counter:
SET user:id 1000
INCR user:id
(integer) 1001
Can I use somehow command in command like:
HMSET incr user:id username "Lacresha Renner" gender "female" email "[email protected]"
(error) ERR wrong number of arguments for HMSET
in case that my database automatically count new users in database. Or it's not possible in Redis? Should I do it by hands, like user:1, user:2, user:n? I am working in terminal (MacOS).
Upvotes: 0
Views: 155
Reputation: 10907
HMSET
receives a key name, and pairs of elements names and values.
Your first argument (incr
) is invalid, and the id
part of the second should be explicit id.
e.g.:
HMSET user:1000 username "Lacresha Renner" gender "female" email "[email protected]"
Regarding your first SET
, you should have one key that its whole purpose is a running uid, you should use the reply of INCR
as the new UID for the new user HASH key name (1000 in the above example).
If you never delete users, the value of the running UID will be the number of users in your system. If you do delete users, you should also insert the UID into a SET and remove the UID once you delete the user. In that case, an SCARD
should give you the number of users in your system, and SMEMBERS
(or SSCAN
) will give you all of their UIDs.
Upvotes: 3