com.jn.agileway.redis.core.RedisTemplate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of agileway-redis-springdata2 Show documentation
Show all versions of agileway-redis-springdata2 Show documentation
Provides a large number of convenient redis tools:
distributed locks,
distributed count,
distributed cache,
distributed id generator,
jdk collection implements,
the enhanced RedisTemplate based on a specified key prefix and the agileway-codec module
package com.jn.agileway.redis.core;
import com.jn.agileway.redis.core.script.RedisLuaScript;
import com.jn.agileway.redis.core.script.RedisLuaScriptRepository;
import org.springframework.data.redis.serializer.RedisSerializer;
import java.util.List;
public class RedisTemplate extends org.springframework.data.redis.core.RedisTemplate {
private RedisLuaScriptRepository luaScriptRepository;
public RedisLuaScript findRedisScript(String scriptId) {
if (luaScriptRepository != null) {
return luaScriptRepository.getById(scriptId);
}
return null;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.RedisOperations#execute(org.springframework.data.redis.core.script.RedisScript, java.util.List, java.lang.Object[])
*/
public T executeScript(String scriptId, List keys, Object... args) {
RedisLuaScript redisLuaScript = findRedisScript(scriptId);
if (redisLuaScript != null) {
return execute(redisLuaScript, keys, args);
}
return null;
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.RedisOperations#execute(org.springframework.data.redis.core.script.RedisScript, org.springframework.data.redis.serializer.RedisSerializer, org.springframework.data.redis.serializer.RedisSerializer, java.util.List, java.lang.Object[])
*/
public T executeScript(String scriptId, RedisSerializer> argsSerializer, RedisSerializer resultSerializer, List keys, Object... args) {
RedisLuaScript redisLuaScript = findRedisScript(scriptId);
if (redisLuaScript != null) {
return execute(redisLuaScript, argsSerializer, resultSerializer, keys, args);
}
return null;
}
public RedisLuaScriptRepository getLuaScriptRepository() {
return luaScriptRepository;
}
public void setLuaScriptRepository(RedisLuaScriptRepository luaScriptRepository) {
this.luaScriptRepository = luaScriptRepository;
}
}