当前位置:网站首页>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
边栏推荐
- OJ daily practice - Finish
- PHP & laravel & master several ways of generating token by API and some precautions (PIT)
- RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio
- 校园转转二手市场源码
- 拨号vps会遇到什么问题?
- How to classify proxy IP?
- Analyze the three functions of static proxy IP.
- 拨号服务器是什么,有什么用处?
- Heap overflow of kernel PWN basic tutorial
- How does Axure set the content of the text box to the current date when the page is loaded
猜你喜欢

一些使用代理IP的小技巧。

What problems will you encounter when dialing VPS?

Some tips for using proxy IP.

J-Link RTT使用

使用代理IP是需要注意什么?

Digital collection platform settled in digital collection platform to develop SaaS platform of digital collection

Shardingsphere introduction and sub table usage

Analyze the advantages and disadvantages of tunnel proxy IP.

Question bank and online simulation examination for safety management personnel of hazardous chemical business units in 2022

How can e-procurement become a value-added function in the supply chain?
随机推荐
揭秘被Arm编译器所隐藏的浮点运算
What is a proxy IP pool and how to build it?
Some tips for using proxy IP.
How to initialize "naming and surname" in C language
MySQL basic record
Numerical remapping method (remap)
2022 Saison 6 perfect Kid Model IPA national race Leading the Meta - Universe Track
What is an API interface?
Use of j-link RTT
How to "gracefully" measure system performance
What is a dial-up server and what is its use?
有哪些常见的代理ip问题?
BGP服务器在什么业务场景会被用到?
在使用代理IP前需要了解哪些分类?
【汇编语言】从最底层的角度理解“堆栈”
[leetcode daily question] 396 Rotation function
Dimension C China helping farmers in rural areas warms people's hearts the third stop is jiabaoguo farm
What is a boolean type?
Micro build low code zero foundation introductory course
代理IP可用率是不是等同于代理IP的效率?