
??博客主页:??
欢迎关注:??点赞??收藏留言
系列专栏:??SpringBoot专栏(每日更新)
如果觉得博主的文章还不错的话,请三连支持一下博主。
??欢迎大佬指正,一起 学习!一起加油!




redis-clishutdwnexit

String类型的命令
set key value 设置数据,如果key存在就覆盖get key 获取key对应的值hash类型的命令
hset key filed value 设置filed字段的valuehget key filed 获取filed字段的valuenil 表示为空clear 清屏key* 获取所有的key

注意:导入相关依赖,勾上之后,springboot会自动导入所需的依赖。

redis依赖
org.springframework.boot
spring-boot-starter-data-redis
RedisTemplate提供操作各种数据存储类型的接口API

??测试:
package com.jkj;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
@SpringBootTest
class Springboot10RedisApplicationTests {
@Autowired
private RedisTemplate redisTemplate;
@Test
void set(){
ValueOperations ops = redisTemplate.opsForValue();
ops.set("name","rc");
}
@Test
void get() {
ValueOperations ops = redisTemplate.opsForValue();
Object value = ops.get("name");
System.out.println(value);
}
}


??获取hash值
package com.jkj;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
@SpringBootTest
class Springboot10RedisApplicationTests {
@Autowired
private RedisTemplate redisTemplate;
@Test
void hset(){
HashOperations hash = redisTemplate.opsForHash();
hash.put("person","name","xfx");
hash.put("person","name1","xmg");
}
@Test
void hget() {
HashOperations hash = redisTemplate.opsForHash();
Object o = hash.get("person", "name");
System.out.println(o);
}
}

StringRedisTemplate以字符串作为key和value??测试:
package com.jkj;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
@SpringBootTest
public class StringRedisApplication {
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Test
void get(){
ValueOperations ops = stringRedisTemplate.opsForValue();
String name = ops.get("name");
System.out.println(name);
}
}
??验证是否等效

??运行测试

导入依赖
redis.clients jedis配置客户端属性
spring:
redis:
host: localhost
port: 6379
client-type: jedis
配置客户端专用属性
spring:
redis:
host: localhost
port: 6379
client-type: lettucelettuce:
pool:
max-active: 16
jedis:
pool:
max-active: 16

先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦