<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version><!--版本号可根据实际情况填写-->
</dependency>
public static void main(String[] args) {
Jedis jedis = new Jedis("127.0.0.1");
jedis.set("key1","value2");
System.out.println( jedis.get("key1"));//value2
String set = jedis.set("key1", "value1", SetParams.setParams().nx());//加锁
System.out.println("返回set:"+set);//null
System.out.println(jedis.get("key1"));//value2
jedis.del("key1");//删除key
String set2 = jedis.set("key1", "value2", SetParams.setParams().nx());//加锁
System.out.println(set2);//ok
System.out.println(jedis.get("key1"));//value2
}