Is it possible to use the Redis command EVAL SHA command with Spring-Data Redis?
We are successfully using EVAL
with execute command: redisTemplate.execute(script, null, args);
,
but it seems to put great overhead to transfer script to the Redis server each time.
Is it possible to store the script once and run it based on its SHA, using Spring-Data Redis?
The default ScriptExecutor optimizes performance by retrieving the SHA1 of the script and attempting first to run evalsha, falling back to eval if the script is not yet present in the Redis script cache.
see spring-data redis docs
The case is that "when we have a master/slave configuration, even though i have installed the same script on both servers and call the master with evalsha, the master forwards the entire script to the slave with an eval command every time".
see this thread
maybe you can do like this:
final String scriptString1= script1.getScriptAsString();
redisTemplate.execute(new RedisCallback<String>(){
@Override
public String doInRedis(RedisConnection connection) throws DataAccessException {
DefaultStringRedisConnection newConnection = new DefaultStringRedisConnection(connection);
return newConnection.scriptLoad(scriptString1);
}
});
DefaultStringRedisConnection has the method "scriptLoad" and allows you to load your script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With