redisTemplate:
string lockKey = "product_101"
string clientID = UUID.randomUUID().toString()
bool result = redisTemplate.opsForValue().setIfAbsent(lockKey,clientID,10,TimeUnit.SECONDS)
if(!result)
{
return "error_code"
}
try{
//业务逻辑
}finally{
if(clientID.equals(redisTemplate.opsForValue().get(lockKey)))
{
redisTemplate.delete(lockKey)
}
}
与注意事项对应关系如下所示
https://www.cnblogs.com/dengliang356a/p/17508140.html
redisson:
redissonLock = redisson.getLock(lockKey);
redissonLock.lock();
try{
// 逻辑
}finally{
redissonLock.unlock();
}
标签:redisson,锁样,redis,clientID,result,redissonLock,lockKey,redisTemplate,分布式
From: https://www.cnblogs.com/dengliang356a/p/17508326.html