当前位置:网站首页>006_redis_jedis快速入门
006_redis_jedis快速入门
2022-04-23 02:02:00 【_yummy_】
006_redis_jedis快速入门
1、新建一个maven项目
2、引入依赖
3、建立连接
4、测试string
5、释放资源
具体代码如图所示:
- 引入依赖:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jedis-demo</groupId>
<artifactId>jedis-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!--jedis依赖-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
<!--引入单元测试-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
- 创建测试类
package com.ym.test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
/** * @author: LYM * @description * @version: V1.0 * @date: 2022/4/20 16:57 */
public class JedisTest {
//引入依赖
private Jedis jedis;
/** * 建立连接 */
@BeforeEach
void setUp() {
//建立连接
jedis=new Jedis("10.223.31.215",6379);
//设置密码
//选择库
jedis.select(0);
}
/** * 操作jedis */
@Test
void test() {
//存入数据
String set = jedis.set("name", "蜜蜂");
//打印数据
System.out.println("name="+set);
//获取数据
String name = jedis.get("name");
System.out.println("name="+name);
}
/** * 释放资源 */
@AfterEach
void tearDown() {
if(jedis!=null){
jedis.close();
}
}
}
- 测试HashSet类型
@Test
void testHash() {
//插入hash数据
jedis.hset("user:1","name","Jack");
jedis.hset("user:1","age","21");
//获取数据
Map<String,String> map = jedis.hgetAll("user:1");
System.out.println(map);
}
Jedis的使用步骤总结:
- (1)引入依赖
- (2)创建Jedis对象,建立连接
- (3)使用Jedis,方法名要与Redis保持一致
- (4)释放资源
蜜蜂打卡第二天~
版权声明
本文为[_yummy_]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43890515/article/details/124301788
边栏推荐
- EBS:PO_EMPLOYEE_HIERARCHIES_ALL
- What is BGP server and what are its advantages?
- 关于局域网浅谈
- 2022.4.10-----leetcode. eight hundred and four
- Nanny level tutorial on building personal home page (II)
- Introduction to esp32 Bluetooth controller API
- Is CICC fortune a company with CICC? Is it safe
- 不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
- [Dahua cloud native] micro service chapter - service mode of five-star hotels
- 批处理多个文件合成一个HEX
猜你喜欢
Is the availability of proxy IP equal to the efficiency of proxy IP?
FL studio20. 8 the latest Chinese version installation and download graphic tutorial
Digital collection platform settled in digital collection platform to develop SaaS platform of digital collection
浅析静态代理ip的三大作用。
89 logistic回归用户画像用户响应度预测
搭建个人主页保姆级教程(二)
ESP32使用freeRTOS的消息队列
NPM yarn startup error [resolved]
Basic knowledge of software testing, you can meet the interviewer after reading it
Error in face detection and signature of Tencent cloud interface
随机推荐
Nanny level tutorial on building personal home page (II)
在使用代理IP前需要了解哪些分类?
What is a makefile file?
What is BGP server and what are its advantages?
中金财富跟中金公司是一家公司吗,安全吗
Campus transfer second-hand market source code
MySQL basic record
PHP & laravel & master several ways of generating token by API and some precautions (PIT)
leetcode:27. 移除元素【count remove小操作】
BGP服务器在什么业务场景会被用到?
Virtual serial port function of j-link V9 using skills
What is a proxy IP pool and how to build it?
【汇编语言】从最底层的角度理解“堆栈”
Is CICC fortune a company with CICC? Is it safe
Analyze the three functions of static proxy IP.
PID精讲
How to classify proxy IP?
Numerical remapping method (remap)
Today will finally write system out. Println()
C语言实现Base64编码/解码