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?
Using Redis to store user information
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. –
Gent
Yeah, after thinking about it a sorted set is a little silly, thanks! –
Thaumaturgy
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):
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] } } –
Luca
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.
© 2022 - 2024 — McMap. All rights reserved.