redis 锁分类
- INCR、SETNX、SET
1 |
|
1 |
|
1 |
|
锁临界问题
- 解决方案 【循环锁】
1 |
|
{———-}
封装spring-data-redis操作redis分布式锁
1 | /** |
this.execute(new RedisCallback
//获取redisnativeConnection 初始化为 JedisCommands返回操作类
JedisCommands commands = (JedisCommands) connection.getNativeConnection();
//使用commands操作类设置数据锁
return commands.set(redisLock.getKey(), redisLock.getValue(), “NX”, “PX”, redisLock.getLockExpireTime());
1 |
|
释放锁 调用spring-data-redis封装类 ResdTemplate.excute()
返回类型初始化为 JedisCluster 或者 Jedis操作类 调用 eval方法 解锁数据