Problems encountered in redis
/** * 为指定KEY设置List值 * @param key * @param list * @return */ public boolean setListByKey(String key, List<?> list, Long expires){ if(null==key){ return false; } redisTemplate.opsForList().rightPushAll(key, list); return redisTemplate.expire(key, expires, TimeUnit.SECONDS); }
Wherein redisTemplate.opsForList (). RightPushAll (Key, List)
rightPushAll required rightPushAll (K key, Collection <V > values), but before the actual call a method rightPushAll (K key, V ... values
public Long rightPushAll(K key, V... values) { final byte[] rawKey = rawKey(key); final byte[][] rawValues = rawValues(values); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { return connection.rPush(rawKey, rawValues); } }, true); } @Override public Long rightPushAll(K key, Collection<V> values) { final byte[] rawKey = rawKey(key); final byte[][] rawValues = rawValues(values); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { return connection.rPush(rawKey, rawValues); } }, true); }
Solution
forced to modify the parameters
public boolean setListByKey(String key, List<?> list, Long expires){ if(null==key){ return false; } redisTemplate.opsForList().rightPushAll(key, (Collection)list); return redisTemplate.expire(key, expires, TimeUnit.SECONDS); }