10

I'm building a simple game type application where I have user authentication. I'm planning on using Redis for my database, and I was wondering what the best practice was to store users? What I understand is that I'll need a list or sorted set to store the users, and each user would be a hashmap. Is this the preferred method of storing users or is there a more optimal way?

2
  • Your should store the data in Redis based on how you're going to access it. A Hash per user usually makes sense. The Sorted Set may or may not fit here, depending on what you are trying to do. Commented Jul 31, 2015 at 7:51
  • Yeah, after thinking about it a sorted set is a little silly, thanks! Commented Jul 31, 2015 at 15:01

2 Answers 2

9

A hash per user works best in most cases. Redis documentation on data types mentions:

Redis Hashes are maps between string fields and string values, so they are the perfect data type to represent objects (e.g. A User with a number of fields like name, surname, age, and so forth):

Sign up to request clarification or add additional context in comments.

1 Comment

Could you help me, please? I've role in user data, do you know how to save this data in redis hash? user: {"username": "Abc" "password:"123", roles: { "app": [1,2,3,4,5,6] } }
0

Single hashmap per user is enough to store string/number/boolean type variables as string. If you want to store array per user, string/number/boolean array, you should also use a set or list per user. If you want to store object array per ser, i think you should store each object as a hashmap and store keys of these hashmaps in a set or list for each user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.