链接redis的中间件
导入依赖
<!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.5.1</version> </dependency> // fastjson <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.75</version> </dependency>
java
Jedis jedis=new Jedis("127.0.0.1",6379); //获取链接 jsonobject jsonobject=new jsonobject(); jsonobject.put("hello","world"); //开启事务 Transaction multi=jedis.multi(); String str =jsonobject.tojsonstring(); //将JSON转换为字符串 multi.set("user1",str); multi.exec(); //执行事务 multi.discard(); //放弃事务 jedis.close(); //关闭链接
所有的命令和redis是一样的
jedis.**** 是一样的