Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use EVAL SHA with spring-data redis?

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?

like image 848
Bartek Avatar asked May 16 '14 05:05

Bartek


2 Answers

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

like image 72
Bartek Avatar answered Oct 03 '22 20:10

Bartek


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.

like image 29
user6096406 Avatar answered Oct 03 '22 22:10

user6096406