Redisson RScoredSortedSet Objects Equality
See original GitHub issueI’m using Redisson library for my Java Redis client and currently implementing RScoredSortedSet data structure. I want to update the score of existing element object with the new one after changing some of its instance properties, but it didn’t work as expected. It inserted as the new element instead of overriding the old one. I suspect my it’s because how the Redis object comparison works.
Data model:
@Data
@Builder
@AllArgsConstructor
public class QueueItem implements Serializable {
    private String name;
    private int count;
    private boolean running;
}
Driver code:
RedissonClient client = Redisson.create();
RScoredSortedSet<QueueItem> queue = client.getScoredSortedSet("myQueue");
QueueItem item = QueueItem.builder().name("Item 1").build();
queue.add(10, item);
item.setCount(1);
queue.add(20, item);
System.out.println("Size: " + queue.size()); // Produced output --> Size: 2
client.shutdown();
I also tried with overriding the equals and hashcode methods of the model, still didn’t work. I read this: https://github.com/redisson/redisson/issues/3300#issuecomment-777224106 and turns out Redis doesn’t invoke those methods for its object comparator.
Is there any better way than removing it first and then re-adding it for changing the element score? Because I think it can cause some delays during the process.
Issue Analytics
- State:
 - Created a year ago
 - Comments:5 (3 by maintainers)
 

Top Related StackOverflow Question
Done
Yes, it is. The score remains the same with previous.