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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With