Skip to content

ZSetOperations range*WithScores do not maintain set ordering with a Glide cluster connection #36

@storance-r7

Description

@storance-r7

I was trying out the pre-release 0.1.0 version, and I noticed the range*WithScores methods on ZSetOperations do not maintain the set's ordering when using a clustered glide connection. These methods do return a set that iterates in the correct order when using a standalone glide connection. The regular range methods (e.g. range, rangeByScore) work correctly for both cluster and standalone connections.

Here is a little snippet that demonstrates the problem:

// clusterConnectionFactory is a ValkeyGlideConnectionFactory setup to connect to a valkey cluster
StringValkeyTemplate template = new StringValkeyTemplate(clusterConnectionFactory);
ZSetOperations<String, String> opsForZSet = template.opsForZSet();

opsForZSet.add("testKey", "value1", 2.0);
opsForZSet.add("testKey", "value2", 1.0);
opsForZSet.add("testKey", "value3", 4.0);
opsForZSet.add("testKey", "value4", 3.0);

// this returns the expected ordering of [value2, value2, value4, value3]
Set<String> rangeResult = opsForZSet.range("testKey", 0, 3);

// this returns what looks like a random ordering
Set<TypedTuple<String>> rangeWithScoresResult = opsForZSet.rangeWithScores("testKey", 0, 3);

I think this is related to this glide client issue. The ZRANGE ... WITHSCORES command returns a Map, and so ClusterValue is treating it as a multi-value. This means ClusterValue ends up calling Map.copyOf() on the result which does not maintain the iteration order of the map being copied.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions