Reputation: 314
i got a list of user name and user id. i want to group the user name by initial. the key will be the user name, so i can get user id from the user name and check if user exist or not.
what is the best data type to use for this? i'm thinking of hash, but any other recommendation? can you tell me why should i choose that data type?
thanks!
Upvotes: 0
Views: 141
Reputation: 3518
I was just playing with that. So here is what I got:
> set alias:tamer 1000
"OK"
> set alias:tansel 1001
"OK"
> hmset uid:1000 alias tamer age 45
"OK"
> hmset uid:1001 alias tansel age 39
"OK"
> hset uid:1000 pass x1x2x3
true
============================
> get alias:tamer
"1000"
> hget uid:1000 alias
"tamer"
hgetall uid:1000
{"alias":"tamer","age":"45","pass":"x1x2x3"}
> hgetall uid:1001
{"alias":"tansel","age":"39"}
> hvals uid:1000
["tamer","45","x1x2x3"]
> hkeys uid:1000
["alias","age","pass"]
So if someone is trying to log in they will give you alias and pass
You would then check if the alias exists, like so:
> get alias:tamer
"1000"
We are checking if uid:tamer is in the database. The answer is yes and the uid # is 1000
Lets get the rest of the uid info:
> hgetall uid:1000
{"alias":"tamer","age":"45","pass":"x1x2x3"}
OR just the password:
> hget uid:1000 pass
"x1x2x3"
Does this answer your question?
Upvotes: 1