mojoo
mojoo

Reputation: 77

saving user data in redis - data structure

I'm wondering what will be the best way to save the data structure of users in redis. should I use hash or string?

this is what I did:

users:$email:fname
users:$email:lname 
users:$email:username
users:$email:password

the email is the unique id (to enable future multiple servers) so I have another string that saves all the emails: emails:$email

Also I have a username:$username to store all the usernames for easy searching

Is that the way to go?

I you can point me to a good resource to see the similar data structures of say a blog site that would be wonderful!

Upvotes: 1

Views: 301

Answers (1)

Didier Spezia
Didier Spezia

Reputation: 73206

I would use a hash object here.

While you can use strings as you proposed, it is more interesting to aggregate the various fields defining a user in a single object. With a hash, it is easier to delete, expire, retrieve a single user. It is also much more memory efficient.

Upvotes: 1

Related Questions