redis的基础命令很多,大部分我们都可以在官网上找到,真的用的时候可以去官网找,不用全部记住这些命令
redis_1">redis通用的基础命令的使用
代码测试
string类型常见的命令
key值的结构,可以区分不同的需求不同的业务名字
hash类型
创建hash结构的redis数据
redis_21">springboot项目中连接redis
添加依赖
<dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>3.7.0</version>
</dependency>
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><scope>test</scope>
</dependency>
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId>
</dependency>
- Jedis测试类
package com.gaofeng;import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;/*** @author gaofeng* @date 2025-01-07 - 20:22*/
@Slf4j
public class JedisTest {private Jedis jedis;@BeforeEachvoid setup(){jedis = new Jedis("192.168.1.102", 6379);
// jedis.auth("123456");jedis.select(0);}@Testvoid testJedis(){// 存入数据String result = jedis.set("name", "张翠山222");String name = jedis.get("name");log.info("name = {} ", name);}@AfterEachvoid tearDown(){if(jedis !=null){jedis.close();}}
}
@Test
void testHash(){// 存入jedis.hset("gaofeng:test1:1","name","张三丰");jedis.hset("gaofeng:test1:1","age","100");// 取出Map<String, String> map = jedis.hgetAll("gaofeng:test1:1");log.info("mapPerson = {} ",map);}
存储hash数据的实现
这样,我们就把数据存储到redis中了