@Component public class redisTest{ @Autowired private RedisTemplate<String, Object> redisTemplate; @PostConstruct public void test(){ //删除之前redis中的数据 redisTemplate.delete(redisTemplate.keys("testKey*")); //redis上加key为“testKey”,值为“测试redi”的数据 redisTemplate.opsForValue().set("testKey:","测试redis") } }
pom.xml文件
<redisson.version>3.13.4</redisson.version> <dependency> <groupId>org.redisson</groupId> <artifactId>redisson</artifactId> <version>${redisson.version} </version> </dependency>