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); }
其中的redisTemplate.opsForList().rightPushAll(key,list)
rightPushAll需要使用rightPushAll(K key, Collection<V> values) ,但是实际调用了前一个方法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); }
解决方式
强制修改参数
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); }