# 一步步实现单机redis的分布式锁(setnx) # 1. 准备工作 # 1.1 定义常量 public class LockConstants { public static final String OK "OK"; /** NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the key if it already exist. **/ …
最近是一直在研究redis,本篇则主要想谈谈对redis的锁的理解。 文章目录 一、SETNX命令的使用二、SET实现1)命令说明:2)set get 可以对已经存在的值重新赋值3)可以设置过期时间 ex ttl4)NX 已经存在的值不能再次赋值5&…