🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ package com.nobb.util.cache; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; @Component public class RedisCache { //jdk 序列化 @Autowired private RedisTemplate redisTemplate; //string 序列化,推荐这个 @Autowired private StringRedisTemplate stringRedisTemplate; public Integer set(String key,String value){ stringRedisTemplate.opsForValue().set(key,value); return 1; } public String get(String key){ return stringRedisTemplate.opsForValue().get(key); } } ~~~