lua脚本:
public Integer incrEX(String key, long defaultExpire){
String script = "local current = redis.call('incr',KEYS[1]);" +
" local t = redis.call('ttl',KEYS[1]); " +
"if t == -1 then " +
"redis.call('expire',KEYS[1],ARGV[1]) " +
"end; " +
"return current";
Object result = jedisCluster.eval(script, Collections.singletonList(key), Collections.singletonList(String.valueOf(defaultExpire)));
return Integer.valueOf(result.toString());
}