Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
* @author Jeonggyu Choi
* @author Mingi Lee
* @author Yordan Tsintsov
* @author won-seoop
*/
@NullUnmarked
@SuppressWarnings({ "ConstantConditions", "deprecation" })
Expand Down Expand Up @@ -1358,18 +1359,36 @@ public <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]... k
return convertAndReturn(delegate.eval(script, returnType, numKeys, keysAndArgs), Converters.identityConverter());
}

@Override
public <T> T evalReadOnly(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return convertAndReturn(delegate.evalReadOnly(script, returnType, numKeys, keysAndArgs),
Converters.identityConverter());
}

@Override
public <T> T evalSha(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return convertAndReturn(delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs),
Converters.identityConverter());
}

@Override
public <T> T evalShaReadOnly(String scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return convertAndReturn(delegate.evalShaReadOnly(scriptSha1, returnType, numKeys, keysAndArgs),
Converters.identityConverter());
}

@Override
public <T> T evalSha(byte[] scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return convertAndReturn(delegate.evalSha(scriptSha1, returnType, numKeys, keysAndArgs),
Converters.identityConverter());
}

@Override
public <T> T evalShaReadOnly(byte[] scriptSha1, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return convertAndReturn(delegate.evalShaReadOnly(scriptSha1, returnType, numKeys, keysAndArgs),
Converters.identityConverter());
}

//
// String methods
//
Expand Down Expand Up @@ -2546,6 +2565,14 @@ public <T> T eval(String script, ReturnType returnType, int numKeys, String... k
return eval(serialize(script), returnType, numKeys, serializeMulti(keysAndArgs));
}

/**
* NOTE: This method will not deserialize Strings returned by Lua scripts, as they may not be encoded with the same
* serializer used here. They will be returned as byte[]s
*/
public <T> T evalReadOnly(String script, ReturnType returnType, int numKeys, String... keysAndArgs) {
return evalReadOnly(serialize(script), returnType, numKeys, serializeMulti(keysAndArgs));
}

/**
* NOTE: This method will not deserialize Strings returned by Lua scripts, as they may not be encoded with the same
* serializer used here. They will be returned as byte[]s
Expand All @@ -2554,6 +2581,14 @@ public <T> T evalSha(String scriptSha1, ReturnType returnType, int numKeys, Stri
return evalSha(scriptSha1, returnType, numKeys, serializeMulti(keysAndArgs));
}

/**
* NOTE: This method will not deserialize Strings returned by Lua scripts, as they may not be encoded with the same
* serializer used here. They will be returned as byte[]s
*/
public <T> T evalShaReadOnly(String scriptSha1, ReturnType returnType, int numKeys, String... keysAndArgs) {
return evalShaReadOnly(scriptSha1, returnType, numKeys, serializeMulti(keysAndArgs));
}

@Override
public Long time() {
return convertAndReturn(this.delegate.time(), Converters.identityConverter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
* @author Tihomir Mateev
* @author Mingi Lee
* @author Yordan Tsintsov
* @author won-seoop
* @since 2.0
*/
@Deprecated
Expand Down Expand Up @@ -2023,20 +2024,41 @@ default <T> T eval(byte[] script, ReturnType returnType, int numKeys, byte[]...
return scriptingCommands().eval(script, returnType, numKeys, keysAndArgs);
}

/** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
@Override
@Deprecated
default <T> T evalReadOnly(byte[] script, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return scriptingCommands().evalReadOnly(script, returnType, numKeys, keysAndArgs);
}

/** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
@Override
@Deprecated
default <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return scriptingCommands().evalSha(scriptSha, returnType, numKeys, keysAndArgs);
}

/** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
@Override
@Deprecated
default <T> T evalShaReadOnly(String scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return scriptingCommands().evalShaReadOnly(scriptSha, returnType, numKeys, keysAndArgs);
}

/** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
@Override
@Deprecated
default <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return scriptingCommands().evalSha(scriptSha, returnType, numKeys, keysAndArgs);
}

/** @deprecated in favor of {@link RedisConnection#scriptingCommands()}. */
@Override
@Deprecated
default <T> T evalShaReadOnly(byte[] scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return scriptingCommands().evalShaReadOnly(scriptSha, returnType, numKeys, keysAndArgs);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Christoph Strobl
* @author David Liu
* @author Mark Paluch
* @author won-seoop
* @see RedisCommands
*/
@NullUnmarked
Expand Down Expand Up @@ -79,6 +80,22 @@ public interface RedisScriptingCommands {
<T> T eval(byte @NonNull [] script, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs);

/**
* Evaluate given read-only {@code script}.
*
* @param script must not be {@literal null}.
* @param returnType must not be {@literal null}.
* @param numKeys
* @param keysAndArgs must not be {@literal null}.
* @return script result. {@literal null} when used in pipeline / transaction.
* @since 4.1
* @see <a href="https://redis.io/commands/eval_ro">Redis Documentation: EVAL_RO</a>
*/
default <T> T evalReadOnly(byte @NonNull [] script, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs) {
throw new UnsupportedOperationException("EVAL_RO is not supported");
}

/**
* Evaluate given {@code scriptSha}.
*
Expand All @@ -92,6 +109,22 @@ <T> T eval(byte @NonNull [] script, @NonNull ReturnType returnType, int numKeys,
<T> T evalSha(@NonNull String scriptSha, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs);

/**
* Evaluate given read-only {@code scriptSha}.
*
* @param scriptSha must not be {@literal null}.
* @param returnType must not be {@literal null}.
* @param numKeys
* @param keysAndArgs must not be {@literal null}.
* @return script result. {@literal null} when used in pipeline / transaction.
* @since 4.1
* @see <a href="https://redis.io/commands/evalsha_ro">Redis Documentation: EVALSHA_RO</a>
*/
default <T> T evalShaReadOnly(@NonNull String scriptSha, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs) {
throw new UnsupportedOperationException("EVALSHA_RO is not supported");
}

/**
* Evaluate given {@code scriptSha}.
*
Expand All @@ -105,4 +138,20 @@ <T> T evalSha(@NonNull String scriptSha, @NonNull ReturnType returnType, int num
*/
<T> T evalSha(byte @NonNull [] scriptSha, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs);

/**
* Evaluate given read-only {@code scriptSha}.
*
* @param scriptSha must not be {@literal null}.
* @param returnType must not be {@literal null}.
* @param numKeys
* @param keysAndArgs must not be {@literal null}.
* @return script result. {@literal null} when used in pipeline / transaction.
* @since 4.1
* @see <a href="https://redis.io/commands/evalsha_ro">Redis Documentation: EVALSHA_RO</a>
*/
default <T> T evalShaReadOnly(byte @NonNull [] scriptSha, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs) {
throw new UnsupportedOperationException("EVALSHA_RO is not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
* @author Jeonggyu Choi
* @author Mingi Lee
* @author Yordan Tsintsov
* @author won-seoop
* @see RedisCallback
* @see RedisSerializer
* @see StringRedisTemplate
Expand Down Expand Up @@ -2983,6 +2984,23 @@ Long geoSearchStore(String destKey, @NonNull String key, @NonNull GeoReference<S
<T> T eval(@NonNull String script, @NonNull ReturnType returnType, int numKeys,
@NonNull String @NonNull... keysAndArgs);

/**
* Evaluate given read-only {@code script}.
*
* @param script must not be {@literal null}.
* @param returnType must not be {@literal null}.
* @param numKeys
* @param keysAndArgs must not be {@literal null}.
* @return
* @since 4.1
* @see <a href="https://redis.io/commands/eval_ro">Redis Documentation: EVAL_RO</a>
* @see RedisScriptingCommands#evalReadOnly(byte[], ReturnType, int, byte[]...)
*/
default <T> T evalReadOnly(@NonNull String script, @NonNull ReturnType returnType, int numKeys,
@NonNull String @NonNull... keysAndArgs) {
throw new UnsupportedOperationException("EVAL_RO is not supported");
}

/**
* Evaluate given {@code scriptSha}.
*
Expand All @@ -2997,6 +3015,23 @@ <T> T eval(@NonNull String script, @NonNull ReturnType returnType, int numKeys,
<T> T evalSha(@NonNull String scriptSha, @NonNull ReturnType returnType, int numKeys,
@NonNull String @NonNull... keysAndArgs);

/**
* Evaluate given read-only {@code scriptSha}.
*
* @param scriptSha must not be {@literal null}.
* @param returnType must not be {@literal null}.
* @param numKeys
* @param keysAndArgs must not be {@literal null}.
* @return
* @since 4.1
* @see <a href="https://redis.io/commands/evalsha_ro">Redis Documentation: EVALSHA_RO</a>
* @see RedisScriptingCommands#evalShaReadOnly(String, ReturnType, int, byte[]...)
*/
default <T> T evalShaReadOnly(@NonNull String scriptSha, @NonNull ReturnType returnType, int numKeys,
@NonNull String @NonNull... keysAndArgs) {
throw new UnsupportedOperationException("EVALSHA_RO is not supported");
}

/**
* Assign given name to current connection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import redis.clients.jedis.commands.JedisBinaryCommands;
import redis.clients.jedis.commands.ScriptingKeyPipelineBinaryCommands;

import java.util.Arrays;
import java.util.List;

import org.jspecify.annotations.NonNull;
Expand All @@ -31,6 +32,7 @@
* @author Mark Paluch
* @author Ivan Kripakov
* @author Tihomir Mateev
* @author won-seoop
* @since 2.0
*/
@NullUnmarked
Expand Down Expand Up @@ -97,12 +99,35 @@ public <T> T eval(byte @NonNull [] script, @NonNull ReturnType returnType, int n
.getOrElse(converter, () -> converter.convert(null));
}

@Override
@SuppressWarnings("unchecked")
public <T> T evalReadOnly(byte @NonNull [] script, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs) {

Assert.notNull(script, "Script must not be null");

byte[][] keys = extractScriptKeys(numKeys, keysAndArgs);
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);

JedisScriptReturnConverter converter = new JedisScriptReturnConverter(returnType);
return (T) connection.invoke()
.from(j -> j.evalReadonly(script, Arrays.asList(keys), Arrays.asList(args)),
p -> p.evalReadonly(script, Arrays.asList(keys), Arrays.asList(args)))
.getOrElse(converter, () -> converter.convert(null));
}

@Override
public <T> T evalSha(@NonNull String scriptSha1, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs) {
return evalSha(JedisConverters.toBytes(scriptSha1), returnType, numKeys, keysAndArgs);
}

@Override
public <T> T evalShaReadOnly(@NonNull String scriptSha1, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs) {
return evalShaReadOnly(JedisConverters.toBytes(scriptSha1), returnType, numKeys, keysAndArgs);
}

@Override
@SuppressWarnings("unchecked")
public <T> T evalSha(byte @NonNull [] scriptSha, @NonNull ReturnType returnType, int numKeys,
Expand All @@ -116,4 +141,30 @@ public <T> T evalSha(byte @NonNull [] scriptSha, @NonNull ReturnType returnType,
.getOrElse(converter, () -> converter.convert(null));
}

@Override
@SuppressWarnings("unchecked")
public <T> T evalShaReadOnly(byte @NonNull [] scriptSha, @NonNull ReturnType returnType, int numKeys,
byte @NonNull [] @NonNull... keysAndArgs) {

Assert.notNull(scriptSha, "Script digest must not be null");

byte[][] keys = extractScriptKeys(numKeys, keysAndArgs);
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);

JedisScriptReturnConverter converter = new JedisScriptReturnConverter(returnType);
return (T) connection.invoke()
.from(j -> j.evalshaReadonly(scriptSha, Arrays.asList(keys), Arrays.asList(args)),
p -> p.evalshaReadonly(scriptSha, Arrays.asList(keys), Arrays.asList(args)))
.getOrElse(converter, () -> converter.convert(null));
}

private static byte[][] extractScriptKeys(int numKeys, byte[]... keysAndArgs) {
return numKeys > 0 ? Arrays.copyOfRange(keysAndArgs, 0, numKeys) : new byte[0][0];
}

private static byte[][] extractScriptArgs(int numKeys, byte[]... keysAndArgs) {
return keysAndArgs.length > numKeys ? Arrays.copyOfRange(keysAndArgs, numKeys, keysAndArgs.length)
: new byte[0][0];
}

}
Loading
Loading