Redis-使用 jedis 操作数据

发布于:2024-06-22 ⋅ 阅读:(95) ⋅ 点赞:(0)

1、Jedis简介

"Jedis" 通常是作为 "Java Redis" 的缩写或简称来理解的。Java Embedded Data Structures Interface 表示 Java嵌入式数据结构接口

2、环境准备

在这里插入图片描述

3、创建maven普通项目,导入如下依赖

<?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>com.atguigu</groupId>
    <artifactId>redis-jedis</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.8.1</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>

4、测试JAVA程序和Redis之间的通信

package com.atguigu.jedis;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
public class Test01 {
    @Test
    public void test01(){
        Jedis jedis = new Jedis("192.168.74.148", 6379);
        String pong = jedis.ping();
        System.out.println("pong = " + pong);
        jedis.close();
    }
}

在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到