| | |
| | | package com.ruoyi.framework.redis;
|
| | |
|
| | | import java.util.Collection;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.concurrent.TimeUnit;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.data.redis.core.BoundSetOperations;
|
| | | import org.springframework.data.redis.core.HashOperations;
|
| | | import org.springframework.data.redis.core.RedisTemplate;
|
| | | import org.springframework.data.redis.core.ValueOperations;
|
| | |
| | |
|
| | | /**
|
| | | * spring redis 工具类
|
| | | * |
| | | *
|
| | | * @author ruoyi
|
| | | **/
|
| | | @SuppressWarnings(value = { "unchecked", "rawtypes" })
|
| | |
| | | * 缓存List数据
|
| | | *
|
| | | * @param key 缓存的键值
|
| | | * @param values 待缓存的List数据
|
| | | * @param dataList 待缓存的List数据
|
| | | * @return 缓存的对象
|
| | | */
|
| | | public <T> long setCacheList(final String key, final List<T> dataList)
|
| | |
| | | * @param dataSet 缓存的数据
|
| | | * @return 缓存数据的对象
|
| | | */
|
| | | public <T> long setCacheSet(final String key, final Set<T> dataSet)
|
| | | public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
|
| | | {
|
| | | Long count = redisTemplate.opsForSet().add(key, dataSet);
|
| | | return count == null ? 0 : count;
|
| | | BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
| | | Iterator<T> it = dataSet.iterator();
|
| | | while (it.hasNext())
|
| | | {
|
| | | setOperation.add(it.next());
|
| | | }
|
| | | return setOperation;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 删除Hash中的数据
|
| | | * |
| | | * @param key
|
| | | * @param hKey
|
| | | */
|
| | | public void delCacheMapValue(final String key, final String hKey)
|
| | | {
|
| | | HashOperations hashOperations = redisTemplate.opsForHash();
|
| | | hashOperations.delete(key, hKey);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取多个Hash中的数据
|
| | | *
|
| | | * @param key Redis键
|
| | |
| | |
|
| | | /**
|
| | | * 获得缓存的基本对象列表
|
| | | * |
| | | *
|
| | | * @param pattern 字符串前缀
|
| | | * @return 对象列表
|
| | | */
|