I am using node_redis client for NodeJS. I have structured data that I am currently trying to store in Redis. Whenever I try to add more key values to the same set, it gets overridden. I'm being chasing it for days and I found that I have to add unique members and then I can add data according to them. I did that part by defining unique keys at the user level but I want to create hash keys with company and username combination. So that, when it goes live; it always generates a unique hash for each user.
JSON:
{
"Company": "ABC",
"Users": [
{
"Username": "john@gmail.com",
"Authenticated": false
},
{
"Username": "chris@gmail.com",
"Authenticated": true
},
{
"Username": "shaun@hotmail.com",
"Authenticated": true
}
]
}
What I tried so far:
var message = JSON.parse(jsonMessage);
message.Users.forEach(function(user,i){
redisClient.sadd("users", "user:" + i);
redisClient.hmset("user:" + i, "Username", user.Username, "Authenticated", user.Authenticated);
});
How I put my data according to the company. Where I should put my company and then add its users respectively as I have data that consists of multiple companies.
What should be the exact binding of the company with its users in Redis?