Showing
1 changed file
with
13 additions
and
5 deletions
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component; | @@ -12,6 +12,7 @@ import org.springframework.stereotype.Component; | ||
12 | 12 | ||
13 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
14 | import java.util.ArrayList; | 14 | import java.util.ArrayList; |
15 | +import java.util.Collection; | ||
15 | import java.util.List; | 16 | import java.util.List; |
16 | import java.util.concurrent.TimeUnit; | 17 | import java.util.concurrent.TimeUnit; |
17 | 18 | ||
@@ -73,10 +74,10 @@ public class RedisListCache { | @@ -73,10 +74,10 @@ public class RedisListCache { | ||
73 | 74 | ||
74 | } | 75 | } |
75 | 76 | ||
76 | - public <T> void rightPushAll(String key,String value, long timeout, TimeUnit unit) { | ||
77 | - logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, value, timeout, unit); | 77 | + public <T> void rightPushAll(String key, Collection<T> values, long timeout, TimeUnit unit) { |
78 | + logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, values, timeout, unit); | ||
78 | // 如果是空列表,直接返回 | 79 | // 如果是空列表,直接返回 |
79 | - if (StringUtils.isEmpty(value)) { | 80 | + if (CollectionUtils.isEmpty(values)) { |
80 | return; | 81 | return; |
81 | } | 82 | } |
82 | 83 | ||
@@ -85,8 +86,15 @@ public class RedisListCache { | @@ -85,8 +86,15 @@ public class RedisListCache { | ||
85 | return; | 86 | return; |
86 | } | 87 | } |
87 | try { | 88 | try { |
88 | - yhListOperations.rightPushAll(key, value); | ||
89 | - yHRedisTemplate.longExpire(key, timeout, unit); | 89 | + Collection<String> strValues = new ArrayList<String>(); |
90 | + for (T t : values) { | ||
91 | + String strValue = CacheKeyHelper.value2String(t); | ||
92 | + if (StringUtils.isEmpty(strValue)) { | ||
93 | + continue; | ||
94 | + } | ||
95 | + strValues.add(strValue); | ||
96 | + } | ||
97 | + yhListOperations.rightPushAll(key, strValues); | ||
90 | 98 | ||
91 | } catch (Exception e) { | 99 | } catch (Exception e) { |
92 | logger.warn("rightPushAll redis list operation failed. key is {}", key, e); | 100 | logger.warn("rightPushAll redis list operation failed. key is {}", key, e); |
-
Please register or login to post a comment