Search code examples
javaspring-bootredisspring-data-redis

Will the redis callback be executed in redis and not in my program?


Let say for example I have the following code:

return (long) redisTemplate.execute(new RedisCallback() {
        @Override
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            String redisKey = RedisKeyUtil.getDAUKey(df.format(start), df.format(end));
            connection.bitOp(RedisStringCommands.BitOperation.OR,
                    redisKey.getBytes(), keyList.toArray(new byte[0][0]));
            return connection.bitCount(redisKey.getBytes());
        }
    });

Will this doInredis method be executed in the redis cluster and not in my program?


Solution

  • No. RedisTemplate is just a Springboot helper class that simplifies your Redis data access code, and it is still executing locally in your thread.

    If your use case is all related to basic Redis command, you can use Lua (example code here). However, there is not prefix filtering in list operation, so you probably can also try CompletableFuture so your data processing won't block other operations.