当前位置:网站首页>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
边栏推荐
- Network jitter tool clumsy
- 005_redis_set集合
- [assembly language] understand "stack" from the lowest point of view
- 我国科学家揭示突破水稻产量瓶颈新机制
- How to set computer IP?
- Analyze the three functions of static proxy IP.
- openstack 服务的启动
- 001_redis设置存活时间
- Want to experience homekit smart home? Why don't you take a look at this smart ecosystem
- What business scenarios will the BGP server be used in?
猜你喜欢

Talk about biology live broadcast: Dr. Wang Ziyuan, a lake view biology, exploring hepatitis B with gene therapy
![PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]](/img/ae/a6681df6c3992c7fd588334623901c.png)
PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]

Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield

VMware virtual machine installation openwrt as side route single arm route img image to vmdk

如何选择一台好的拨号服务器?

Is the availability of proxy IP equal to the efficiency of proxy IP?

010_StringRedisTemplate

Introduction to micro build low code zero Foundation (lesson 2)

Nanny level tutorial on building personal home page (II)

什么是api接口?
随机推荐
Why is one plus one equal to two
013_基于Session实现短信验证码登录流程分析
有哪些业务会用到物理服务器?
Is the sinking coffee industry a false prosperity or the eve of a broken situation?
LeetCode 447. Number of boomerangs (permutation and combination problem)
小程序 canvas 画布半圆环
MySQL active / standby configuration binary log problem
leetcode:27. 移除元素【count remove小操作】
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
Arduino esp8266 network upgrade OTA
BGP服务器在什么业务场景会被用到?
leetcode:27. Remove element [count remove]
Consider defining a bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs‘
Makefile文件是什麼?
How to configure iptables to realize local port forwarding
【Chrome扩展程序】content_script的跨域问题
What are the test steps of dynamic proxy IP?
PTA: 浪漫倒影 [二叉树重建] [深度优先遍历]
New book recommendation - IPv6 technology and application (Ruijie version)
C standard library - < time h>