springboot 使用 jedis 连接 Redis 数据库


1. 在 pom.xml 配置文件中添加依赖

        <!-- redis 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <!-- jedis 依赖 -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>

 2. 编写测试方法

    @Test
    void redisTest(){
        // 连接 Redis 数据库 , 获取连接对象
        Jedis jedis = new Jedis("localhost");
        // 向 Redis 数据库写入数据
        jedis.set("name","李四");
        // 读取 Redis 数据库数据
        String name = jedis.get("name");
        // 打印输出
        System.out.println(name);
    }

3. 成功


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM