the lua script is simple:
local current = redis.call("GET", KEYS[2])
if current == ARGV[2]
then redis.call("SET", KEYS[1], ARGV[1])
return true
end
return false
here is the java code:
public static void main(String[] args) {
//
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-redis.xml");
final RedisTemplate<String,String> redisTemplate = applicationContext.
getBean("redisTemplate",RedisTemplate.class);
DefaultRedisScript<Boolean> script=new DefaultRedisScript<>();
ClassPathResource resource=new ClassPathResource("test11.lua");
script.setScriptSource(new ResourceScriptSource(resource));
script.setResultType(Boolean.class);
List<String> keys=new ArrayList();
keys.add("k10");
keys.add("k11");
Boolean result=redisTemplate.execute(script,keys,new String[]{"lala","lala"});
System.out.println(result);
}
Storage of data in redis:
Why do you always return false??