当前位置:网站首页>Redis-Redis在Jedis中的使用
Redis-Redis在Jedis中的使用
2022-07-28 13:55:00 【晚霞虽美不如你】
前言
百度的概念性解答我就不贴了,简单来说,Jedis是Redis官方推荐的Java连接开发工具! 虽然现在的SpringBoot2.×版本已经将Jedis换成了Lettuce,但是我觉得还是有必要了解一下Jedis的使用!
1.如何在java项目中整合Jedis并且连接Redis数据库?
①创建一个Maven项目

②导入Jedis和fastjson依赖,耐心等待下载完成!
<!--导入jedis的包-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
</dependency>
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
③连接Redis测试,此处为了方便测试,连接的是本地的Redis服务,连接远程需要更改配置文件和关闭防火墙,以后会单独弄一篇文章来介绍这个!
// 1、 new Jedis 对象即可
Jedis jedis = new Jedis("127.0.0.1",6379);
// jedis 所有的命令就是我们之前的所有指令
System.out.println(jedis.ping());
如图:

返回PONG,证明连接成功!
④常用的API练习:
// 1、 new Jedis 对象即可
Jedis jedis = new Jedis("127.0.0.1",6379);
jedis.flushDB();//清空当前库的所有数据
jedis.set("name","dingyongjun");
jedis.set("age","23");
jedis.set("high","173");
System.out.println("name:"+jedis.get("name")+"\nage:"+jedis.get("age")+"\nhigh"+jedis.get("high"));
如图:

jedis.lpush("list","1","2","3","4");
System.out.println("list: "+jedis.lrange("list",0,-1));

⑤总结:在Jedis中连接使用Redis,和Redis控制台命令完全一致
边栏推荐
- Detailed explanation of C language student achievement management system [easy to understand]
- SwiftUI 布局 —— 对齐
- Development and definition of software testing
- Thrift 序列化协议浅析
- HCIP第十一天
- How to reduce the resolution of only 3D camera but not UI camera
- 8、 Picker usage drop-down box selection effect
- 468 product planning and promotion plan (150 copies)
- Forage QR code -- online QR code generator
- [ecmascript6] modularization
猜你喜欢

9、 Uni popup usage popup effect at the bottom of the drop-down box

Brief introduction and use of mqtt entry level

天气这么热太阳能发电不得起飞喽啊?喽啊个头……

BGP experiment

2022 low voltage electrician examination questions and answers

Metersphere -- Open Source continuous testing platform
![[ecmascript6] other new interface features](/img/da/377f93d83b6722bf250d270e4eea28.png)
[ecmascript6] other new interface features

ScottPlot入门教程:获取和显示鼠标处的数值

The method of implementing simple student achievement management system with C language

Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it
随机推荐
Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it
实时切换 Core Data 的云同步状态
Node文件操作
Use of formdata object, VAR formdata=new formdata()
Animation mechanism of swiftui
Excel VBA 免密查看VBE加密代码
[ecmascript6] iterator and generator
TDengine 助力西门子轻量级数字化解决方案
Analysis of thrift serialization protocol
Bulk Rename Utility
在 SwiftUI 视图中打开 URL 的若干方法
linux安装mysql
[ecmascript6] proxy and reflection
Open source project - taier1.2 release, new workflow, tenant binding simplification and other functions
十、时间戳
Brief introduction and use of mqtt entry level
SwiftUI 的动画机制
C # read INI file and key value pair operation
Brief introduction of diversity technology
SwiftUI 布局 —— 对齐