前言
请看下面代码:
String key = String.format("test_key:%s", System.currentTimeMillis()/1000);
String key2=key+"_2";
String key3=key+"_3";
List<String> t1=new ArrayList<>();
t1.add("2");
t1.add("3");
t1.add("4");
t1.add("5");
t1.add("1");
redisTemplate.opsForList().leftPushAll(key, t1);
redisTemplate.opsForList().leftPushAll(key3, t1.toArray());
redisTemplate.opsForList().leftPushAll(key2,new String[]{"dfdg","dgdaasdf","gdadfdf"});
其中,那么,请猜测一下各个key里面的内容,
下面开奖了:



结论
leftPushAll可以传 Object… 数组,也可以传 Collection进去。
然后实际上,我这边传 ArrayList这些数组是不行的,必须转换为 [] 这种数组—就是说,api里面的leftPushAll(Collection list)
用不了,具体原因还在查。。。
不过网上资料太少了。。
本文通过一个具体的例子演示了如何使用Redis的List数据结构,并重点介绍了leftPushAll方法的使用技巧及注意事项。

520

被折叠的 条评论
为什么被折叠?



