Reputation: 63
I am currently building a sort of a queue system but I have a few questions designing the system with Redis.
Basically I will have many shops and in each shop, there will be many users.
I would like to record the profile of the user, such as handphone number, queue number, email, timeofqueue.
The queue number has to be in order. The users' queue numbers are also updated when a user in the middle leaves the queue. (meaning when user of queue number 2 leaves, the other users having queue number 3 4 5 6 7, becomes 2 3 4 5 6.
My data would be like this for the shops:
shop1 : {
user1: {
handphone: 4520502124,
name: "david",
time: "11.50AM"
},
user2: {
handphone: 4501250125,
name: "peter",
time: "12.00PM"
},
user3: {
handphone: 401201250,
name: "john",
time: "12.15PM"
}
}
shop2 : {
user1: {
handphone: 12561256126,
name: "andy",
time: "12.00PM"
}
user2: {
handphone: 512561261,
name: "belle",
time: "01.00PM"
}
shop1queue: ["user1","user2","user3"];
shop2queue: ["user1","user2"];
I use hashes to store the users' profiles and i probably can remove them by HDEL. I use sorted sets to hold the queue numbers, and whenever a user in the middle leaves, I can use ZRANK to get the queue number of the other users.
Question:
For my scenario, is using sorted sets for holding the queue numbers the right approach?
If I would like to get all the hash keys in shop1 including the values inside, how do I do that in Redis?
Upvotes: 0
Views: 216
Reputation: 890
Storing the users' details in hashes is a good idea. Then in the sorted set you can use the id
of the user as the member, and the timestamp
as the score. That way, the rank is calculated automatically even if you eliminate some member.
Upvotes: 2