当前位置:网站首页>006_ redis_ Jedis quick start
006_ redis_ Jedis quick start
2022-04-23 02:08:00 【_ yummy_】
006_redis_jedis Quick start
1、 Create a new one maven project

2、 Introduce dependencies
3、 Establishing a connection
4、 test string
5、 Release resources
The specific code is shown in the figure :
- Introduce dependencies :
<?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 rely on -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
<!-- Introduce unit testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
- Create test class
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 {
// Introduce dependencies
private Jedis jedis;
/** * Establishing a connection */
@BeforeEach
void setUp() {
// Establishing a connection
jedis=new Jedis("10.223.31.215",6379);
// Set the password
// Select Library
jedis.select(0);
}
/** * operation jedis */
@Test
void test() {
// In the data
String set = jedis.set("name", " The bees ");
// Print data
System.out.println("name="+set);
// get data
String name = jedis.get("name");
System.out.println("name="+name);
}
/** * Release resources */
@AfterEach
void tearDown() {
if(jedis!=null){
jedis.close();
}
}
}

- test HashSet type
@Test
void testHash() {
// Insert hash data
jedis.hset("user:1","name","Jack");
jedis.hset("user:1","age","21");
// get data
Map<String,String> map = jedis.hgetAll("user:1");
System.out.println(map);
}


Jedis Summary of the use steps of :
- (1) Introduce dependencies
- (2) establish Jedis object , Establishing a connection
- (3) Use Jedis, The method name should be in line with Redis bring into correspondence with
- (4) Release resources
The bee clocked in the next day ~
版权声明
本文为[_ yummy_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230202506695.html
边栏推荐
- EBS:PO_ EMPLOYEE_ HIERARCHIES_ ALL
- Esp32 message queue using FreeRTOS
- 不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
- 每日一题(2022-04-21)——山羊拉丁文
- What is BGP server and what are its advantages?
- tp6阿裏雲短信 window 報 cURL error 60: SSL certificate problem: unable to get local issuer certificate
- 一些使用代理IP的小技巧。
- Want to experience homekit smart home? Why don't you take a look at this smart ecosystem
- Latin goat (20204-2022) - daily question 1
- 想体验HomeKit智能家居?不如来看看这款智能生态
猜你喜欢

005_redis_set集合
![PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]](/img/ae/a6681df6c3992c7fd588334623901c.png)
PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]

How to set computer IP?

006_redis_jedis快速入门

PTA: 点赞狂魔

搭建网站是用物理机还是云主机好?

leetcode:27. 移除元素【count remove小操作】

R language advanced | generalized vector and attribute analysis

Realize linear regression with tensorflow (including problems and solutions in the process)

What is an API interface?
随机推荐
Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools
What is a makefile file?
我国科学家揭示突破水稻产量瓶颈新机制
Latin goat (20204-2022) - daily question 1
想体验HomeKit智能家居?不如来看看这款智能生态
Common formatting problems after word writing
How to write the resume of Software Test Engineer so that HR can see it?
tp6阿里云短信 window 报 cURL error 60: SSL certificate problem: unable to get local issuer certificate
Introduction to esp32 Bluetooth controller API
LeetCode 447. Number of boomerangs (permutation and combination problem)
Shardingsphere broadcast table and binding table
Applet reads files
NPM yarn startup error [resolved]
What is a proxy IP pool and how to build it?
假如404页面是这样的 | 每日趣闻
Consider defining a bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs‘
使用代理IP是需要注意什么?
easyswoole环境配置
How to set computer IP?
Heap overflow of kernel PWN basic tutorial