question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redisson RScoredSortedSet Objects Equality

See original GitHub issue

I’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:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrnikocommented, May 12, 2022

Done

0reactions
justinushermawancommented, Apr 26, 2022

Yes, it is. The score remains the same with previous.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redisson RScoredSortedSet Objects Equality - Stack Overflow
I'm using Redisson library for my Java Redis client and currently implementing RScoredSortedSet data structure. I want to update the score ...
Read more >
RScoredSortedSet.Aggregate (Redisson 3.14.0 API) - javadoc.io
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate...
Read more >
Not able to remove custom object from RScoredSortedSet JAVA
I have code like above in my application. i am not able to remove custom obj from RScoredSortedSet.
Read more >
mrniko/redisson - Gitter
how does the equals work for RSet insertion? Equals method is not used. Object equal as long as thier serialized state are equal....
Read more >
org.redisson.api.RedissonClient.getScoredSortedSet java ...
else if (RScoredSortedSet.class.isAssignableFrom(objectClass)) { collection = redisson.getScoredSortedSet(objectName, codec);
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found