Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing key, value pairs with redis sorted set

I want to store (key, value) pairs in a Redis sorted set (along with the double for ordering). My current option would be to have the sorted set for the keys, and then have another Redis hash that I can store the pairs in. Is there a better/more canonical way to approach this problem?

like image 457
Andrew Avatar asked Sep 16 '25 07:09

Andrew


1 Answers

It highly depends on the planned use of the sorted set. One pattern you might use is to duplicate the data. As in the NoSQL world, normalization is not as critical. What you could do is to concatenate the key with the value in the sorted set. So instead of key: score, you could store key-value: score. The - character can be any delimiter you choose so that you can easily parse. This saves you one trip to the key: value set to fetch the value. Again, it highly depends on the planned use of the sorted set.

like image 140
neurite Avatar answered Sep 18 '25 10:09

neurite