Skip to content

Commit

Permalink
Fixed - Spring Data Redis evalsha doesn't use key for Redis node rout…
Browse files Browse the repository at this point in the history
…ing in Cluster mode. #4561
  • Loading branch information
Nikita Koksharov committed Sep 27, 2022
1 parent e6e961f commit 91268be
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,9 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
Expand Down Expand Up @@ -1800,7 +1802,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1810,7 +1814,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

private static final RedisCommand<Long> PFADD = new RedisCommand<Long>("PFADD");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1819,11 +1819,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1854,7 +1856,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1864,7 +1868,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

private static final RedisCommand<Long> PFADD = new RedisCommand<Long>("PFADD");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1832,11 +1832,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1867,7 +1869,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1877,7 +1881,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1835,11 +1835,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1870,7 +1872,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1880,7 +1884,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,11 +1838,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1873,7 +1875,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1883,7 +1887,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,11 +1838,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1873,7 +1875,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1883,7 +1887,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,11 +1838,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1873,7 +1875,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1883,7 +1887,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1863,11 +1863,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1898,7 +1900,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1908,7 +1912,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1902,11 +1902,13 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
params.add(script);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

protected RedisCommand<?> toCommand(ReturnType returnType, String name) {
RedisCommand<?> c = null;
RedisCommand<?> c = null;
if (returnType == ReturnType.BOOLEAN) {
c = org.redisson.api.RScript.ReturnType.BOOLEAN.getCommand();
} else if (returnType == ReturnType.INTEGER) {
Expand Down Expand Up @@ -1937,7 +1939,9 @@ public <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

@Override
Expand All @@ -1947,7 +1951,16 @@ public <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[
params.add(scriptSha);
params.add(numKeys);
params.addAll(Arrays.asList(keysAndArgs));
return write(null, ByteArrayCodec.INSTANCE, c, params.toArray());

byte[] key = getKey(numKeys, keysAndArgs);
return write(key, ByteArrayCodec.INSTANCE, c, params.toArray());
}

private static byte[] getKey(int numKeys, byte[][] keysAndArgs) {
if (numKeys > 0 && keysAndArgs.length > 0) {
return keysAndArgs[0];
}
return null;
}

@Override
Expand Down

0 comments on commit 91268be

Please sign in to comment.