Skip to content

JedisClusterKeyCommands not sending SORT with STORE modifier #2341

Closed
@Kris-10-0

Description

@Kris-10-0

When in Cluster mode, Jedis is not properly sending out SORT when it has the STORE modifier. It calls SORT without the STORE modifier then adds the result to the key. This causes the result to not be properly stored in the storeKey even if the keys are in the same slot. This can be seen in the code below, which can be found in JedisClusterKeyCommands.java.

@Override
	public Long sort(byte[] key, SortParameters params, byte[] storeKey) {

		Assert.notNull(key, "Key must not be null!");

		List<byte[]> sorted = sort(key, params);
		if (!CollectionUtils.isEmpty(sorted)) {

			byte[][] arr = new byte[sorted.size()][];
			switch (type(key)) {

				case SET:
					connection.setCommands().sAdd(storeKey, sorted.toArray(arr));
					return 1L;
				case LIST:
					connection.listCommands().lPush(storeKey, sorted.toArray(arr));
					return 1L;
				default:
					throw new IllegalArgumentException("sort and store is only supported for SET and LIST");
			}
		}
		return 0L;
	}

I believe in order to fix this. The following code needs to be added after the assert.

		if (ClusterSlotHashUtil.isSameSlotForAllKeys(key, storeKey)) {
			try {
				return connection.getCluster().sort(key, params, storeKey);
			} catch (Exception ex) {
				throw convertJedisAccessException(ex);
			}
		}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions