2

I'm new to Redis and I’m trying to work out which data type is right to store a set of data specific to one user.

The data set would be specific to, say, user 1000 and therefore I might call the type

1000:MatchesMembers

The data type would then hold a list of other users like:

1001, photo, age, name, location, city, country
1003, photo, age, name, location, city, country
1007, photo, age, name, location, city, country
1009, photo, age, name, location, city, country

I have read that hash types are the best to use if possible - Redis set vs hash

If the hash is the best to use, is this how I use it?

var hash = client.GetHash<string>("1000:MatchesMembers");
hash.SetValue("key", "value");

Do I have to set each value individually or can they be set in bulk?

Finally is it possible to pop values out of the hash? I will take around 10 entries each time and would like to remove them once I use them. Is there a way to pop entries off the hash or do I need to read and delete? Would a different data type better suit this functionality?

Thank you very much.

Community
  • 1
  • 1
Adam
  • 19,932
  • 36
  • 124
  • 207

1 Answers1

0

I can't answer to the syntax question, as you did not say which redis driver you are using. So here are information based on Redis commands.

Use HMSET to set all data related to a given user.

HMSET 1001 photo "url of the photo" age 31 name "user name" location "location name" city "city name" country "country name"

Use a set to store the Ids of the users

SADD 1000:MatchesMembers 1001 1003 1007 1009

To remove a user from the Set use SREM

To optimize the insertion of multiple member profiles, use pipeling. Your Redis driver should handle it.

Pascal Le Merrer
  • 5,883
  • 20
  • 35