use of org.springframework.data.redis.core.RedisCallback in project dq-easy-cloud by dq-open-cloud.
the class EcLock method releaseDistributedLock.
/**
* 释放分布式锁
*
* @return 是否释放成功
*/
private boolean releaseDistributedLock() {
RedisCallback<Object> redisCallback = new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
Jedis jedis = (Jedis) connection.getNativeConnection();
return jedis.eval(script, Collections.singletonList(lockName), Collections.singletonList(lockValue));
}
};
Object result = stringRedisTemplateLock.execute(redisCallback);
if (EcBaseUtils.equals(RELEASE_SUCCESS, result)) {
return true;
}
return false;
}
Aggregations