ZSETs are used to store sorted sets in redis. I am using spring-data-redis for ZSetOperations.
All the range methods return Set<> instead of SortedSet<> and I was wondering what's the reasoning behind it?
Also, since these don't return sorted sets, doesn't all the reverse range operations become redundant, since the order is not maintained anyway and we can not just get any element at an index?
I could be missing something very obvious, please excuse my naivete in the matter.
My use case :
I am storing values with dates as score. I want get all the values between two dates, check the count, and use the most recent date.
I was planning to do something like :
// get reverse sorted values, with most recent date being on top
SrotedSet<String> values = zSetOperations.rangeByScore(key, this.getBeginDate(), this.getEndDate());
// check values size and do values.get(0) i.e. the most recent date.
But the return type of rangeByScore is Set, so no 'get' operations.
I'll have to get the range with score and then sort them myself.
Or I'll have to convert to array and get the element.
Or do something like
values.iterator().next()