修改Set可能导致嵌套的问题

pull/30/head
RuoYi 4 years ago
parent dddbaeb5c0
commit ff979772fe

@ -1,11 +1,13 @@
package com.ruoyi.common.redis.service; package com.ruoyi.common.redis.service;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired; 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.HashOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
@ -136,10 +138,15 @@ public class RedisService
* @param dataSet * @param dataSet
* @return * @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); BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
return count == null ? 0 : count; Iterator<T> it = dataSet.iterator();
while (it.hasNext())
{
setOperation.add(it.next());
}
return setOperation;
} }
/** /**

Loading…
Cancel
Save