|  |  | 
 |  |  |  | 
 |  |  | 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; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  |  | 
 |  |  | import java.util.HashMap; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  | import java.util.Set; | 
 |  |  | 
 |  |  |  * redisTemplate封装 | 
 |  |  |  * | 
 |  |  |  */ | 
 |  |  | //@Component | 
 |  |  | @Component | 
 |  |  | public class RedisUtil { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RedisTemplate<String, Object> redisTemplate; | 
 |  |  | //    @Autowired | 
 |  |  | //    private RedisTemplate<String, Object> redisTemplate; | 
 |  |  |  | 
 |  |  |     public RedisUtil(RedisTemplate<String, Object> redisTemplate) { | 
 |  |  |     @Autowired | 
 |  |  |     private RedisTemplate redisTemplate; | 
 |  |  |  | 
 |  |  |     public RedisUtil(RedisTemplate redisTemplate) { | 
 |  |  |         this.redisTemplate = redisTemplate; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取全部数据 | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public HashMap<Object, Object> getRedis() { | 
 |  |  |         Set<String> keys = redisTemplate.keys("*"); | 
 |  |  |         HashMap<Object, Object> map = new HashMap<>(); | 
 |  |  |         for (String key : keys) { | 
 |  |  |             Object value = redisTemplate.opsForValue().get(key); | 
 |  |  |             map.put(key, value); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return map;//返回全部数据集合 | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 普通缓存放入 | 
 |  |  |      * | 
 |  |  |      * @param key   键 |