贴上我的测试类:
package com.paascloud.provider.web;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.concurrent.TimeUnit;
@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTest {
@Autowired
private RedisTemplate redisTemplate;
@MockBean
private EurekaAutoServiceRegistration eurekaAutoServiceRegistration;
@Test
public void testRedisCache(){
String keys="company*";//这个就是key,支持模糊搜索
redisTemplate.opsForValue().set(keys,"this is a test content!",1000, TimeUnit.SECONDS);
String content=redisTemplate.opsForValue().get(keys).toString();
System.out.println("---------》获取到缓存的内容为:"+content);
redisTemplate.delete(redisTemplate.keys(keys+"*"));
Object msg=redisTemplate.opsForValue().get(keys);
if (msg==null){
msg="没有了";
}
System.out.println("---------》移除后内容为:"+msg);
}
}
Java实现批量模糊删除Redis Key 对应的值
最新推荐文章于 2024-08-18 03:31:29 发布