当前位置:网站首页>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
边栏推荐
- 011_RedisTemplate操作Hash
- ThinkPHP kernel development blind box mall source code v2 0 docking easy payment / Alibaba cloud SMS / qiniu cloud storage
- 【汇编语言】从最底层的角度理解“堆栈”
- [hands on learning] network depth v2.1 Sequence model
- Analyze the three functions of static proxy IP.
- New book recommendation - IPv6 technology and application (Ruijie version)
- How to set computer IP?
- 假如404页面是这样的 | 每日趣闻
- 关于局域网浅谈
- What categories do you need to know before using proxy IP?
猜你喜欢
有哪些业务会用到物理服务器?
VMware virtual machine installation openwrt as side route single arm route img image to vmdk
Some tips for using proxy IP.
拨号服务器是什么,有什么用处?
Is it better to use a physical machine or a virtual machine to build a website?
Leetcode46 Full Permutation
What businesses use physical servers?
Arduino esp8266 network upgrade OTA
Want to experience homekit smart home? Why don't you take a look at this smart ecosystem
Heap overflow of kernel PWN basic tutorial
随机推荐
每日一题(2022-04-22)——旋转函数
Introduction to esp32 Bluetooth controller API
有哪些常见的代理ip问题?
小程序 读取文件
R language advanced | generalized vector and attribute analysis
002_Redis_String类型常见的操作命令
LeetCode 447. Number of boomerangs (permutation and combination problem)
Is CICC fortune a state-owned enterprise and is it safe to open an account
Leetcode46 Full Permutation
[Dahua cloud native] micro service chapter - service mode of five-star hotels
用TensorFlow实现线性回归(包括过程中出现的问题及解决方法)
What businesses use physical servers?
Consider defining a bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs‘
浅析静态代理ip的三大作用。
Analyze the three functions of static proxy IP.
拨号vps会遇到什么问题?
[leetcode daily question] 396 Rotation function
009_Redis_RedisTemplate入门
New book recommendation - IPv6 technology and application (Ruijie version)
Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space