0

I need to preserve the ordering of elements added to a SET in Redis. In order to do that, I am using RSortedSet with a custom comparator.

The problem am facing here is, unlike RSetCache I am not able to expire the elements in this SET.

Is there a work-around to achieve this use case ?.

Bala.vrad
  • 53
  • 9

1 Answers1

1

First of all, RSortedSet is implemented on top of a Redis LIST, not a SET. There is a RScoredSortedSet which is implemented on top of a Redis ZSET.

To achieve element expiry, as a work around, you can wrap it with another RExpirable object before adding into the RSortedSet. You just need to do some extra house keeping yourself: when you get an RExpirable object but it does not exist (isExists returns false), it means it is now expired. You can then delete it from the RSortedSet by yourself.

Redisson_RuiGu
  • 1,012
  • 10
  • 13