How to keep sorted data in Redis with repeated item?

I am new to Redis and have the following problem:

Given the given myzset: [[1, "A"], [2, "B"], [3, "C"]]

I want to add [4, "A"] to the set.

While I am using

ZADD myzset 4 "A"

      

because member "A" is already in the set, I go back [[4, "A"], [2, "B"], [3, "C"]]

but not

[[1, "A"], [2, "B"], [3, "C"], [4, "A"]]

How to insert data so that the set is

[[1, "A"], [2, "B"], [3, "C"], [4, "A"]]?

+3


source to share


1 answer


Redis sorted sets (and regular sets) do not allow duplicate items. You should reconsider what you are trying to do (maybe even edit your question to explain the data you store and how you want to get it) and maybe use a different approach and / or data structure.



In cases where it is necessary and makes sense to store a unique element in a sorted set, you usually concatenate some kind of unique member identifier. For example, if you are storing time series (such as measurements from a device), you should store the timestamp as a count and ID: timestamp as a member.

+1


source







All Articles