ÎļþÃû´Ó se-system/src/main/java/com/terra/system/service/all/RedisService.java ÐÞ¸Ä |
| | |
| | | package com.terra.system.service.all; |
| | | package com.terra.common.service; |
| | | |
| | | import com.terra.common.entity.all.SettingData; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | |
| | | * Redisæå¡ç±» |
| | | * @author WWW |
| | | */ |
| | | @Service("redisService") |
| | | @Service |
| | | public class RedisService { |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | /** |
| | | * è·åRedisæ¨¡æ¿ |
| | | * |
| | | * @return |
| | | */ |
| | | public RedisTemplate<String, Object> getRedisTemplate() { |
| | | return redisTemplate; |
| | |
| | | * æ ¹æ®keyè·åvalue |
| | | * |
| | | * @param key é® |
| | | * @return |
| | | */ |
| | | public Object get(String key) { |
| | | return redisTemplate.opsForValue().get(key); |
| | |
| | | * æ¯å¦åå¨key |
| | | * |
| | | * @param key é® |
| | | * @return |
| | | */ |
| | | public boolean hasKey(String key) { |
| | | return redisTemplate.hasKey(key); |
| | |
| | | */ |
| | | public void clearKeys(String subKeyString) { |
| | | Set<String> keys = redisTemplate.keys(subKeyString + "*"); |
| | | if (null != keys && keys.size() > 0) { |
| | | if (!keys.isEmpty()) { |
| | | redisTemplate.delete(keys); |
| | | } |
| | | } |
| | |
| | | */ |
| | | public void clearAll() { |
| | | Set<String> keys = redisTemplate.keys("*"); |
| | | if (null != keys && keys.size() > 0) { |
| | | if (!keys.isEmpty()) { |
| | | redisTemplate.delete(keys); |
| | | } |
| | | } |
| | |
| | | * æ ¹æ®Keyä¿åæ°æ® |
| | | */ |
| | | public <T> void saveListByKey(String key, List<T> list) { |
| | | if (null != list && list.size() > 0) { |
| | | if (null != list && !list.isEmpty()) { |
| | | put(key, list, SettingData.CACHE_EXPIRE, TimeUnit.MINUTES); |
| | | } |
| | | } |
| | |
| | | * æ ¹æ®Keyä¿åæ°æ® |
| | | */ |
| | | public <T> void saveListByKey(String key, List<T> list, Integer minutes) { |
| | | if (null != list && list.size() > 0) { |
| | | if (null != list && !list.isEmpty()) { |
| | | put(key, list, minutes, TimeUnit.MINUTES); |
| | | } |
| | | } |