Redis的Hash数据结构
Redis的散列可以让用户将多个键值对存储到一个Redis键里面。
public interface HashOperations<H,HK,HV>
HashOperations提供一系列方法操作hash:
初始数据://template.opsForHash().put("redisHash","name","tom");
//template.opsForHash().put("redisHash","age",26);
//template.opsForHash().put("redisHash","class","6");//Map<String,Object> testMap = new HashMap();
//testMap.put("name","jack");
//testMap.put("age",27);
//testMap.put("class","1");
//template.opsForHash().putAll("redisHash1",testMap);12345678910
Long delete(H key, Object… hashKeys);
删除给定的哈希hashKeys
使用:System.out.println(template.opsForHash().delete("redisHash","name"));
System.out.println(template.opsForHash().entries("redisHash"));结果:1{class=6, age=28.1}1234
使用:System.out.println(template.opsForHash().hasKey("redisHash","age"));
System.out.println(template.opsForHash().hasKey("redisHash","ttt"));结果:truefalse1234
使用:System.out.println(template.opsForHash().get("redisHash","age"));结果:2612
使用:List<Object> kes = new ArrayList<Object>();
kes.add("name");
kes.add("age");
System.out.println(template.opsForHash().multiGet("redisHash",kes));结果:[jack, 28.1]12345
使用:System.out.println(template.opsForHash().get("redisHash","age"));
System.out.println(template.opsForHash().increment("redisHash","age",1));结果:26271234
使用:System.out.println(template.opsForHash().get("redisHash","age"));
System.out.println(template.opsForHash().increment("redisHash","age",1.1));结果:2728.11234
使用:System.out.println(template.opsForHash().keys("redisHash1"));//redisHash1所对应的散列表为{class=1, name=jack, age=27}结果:[name, class, age]123
使用:System.out.println(template.opsForHash().size("redisHash1"));//redisHash1所对应的散列表为{class=1, name=jack, age=27}结果:3123
使用:System.out.println(template.opsForHash().size("redisHash1"));//redisHash1所对应的散列表为{class=1, name=jack, age=27}结果:3123
使用:Map<String,Object> testMap = new HashMap();
testMap.put("name","jack");
testMap.put("age",27);
testMap.put("class","1");
template.opsForHash().putAll("redisHash1",testMap);
System.out.println(template.opsForHash().entries("redisHash1"));结果:{class=1, name=jack, age=27}1234567
使用:template.opsForHash().put("redisHash","name","tom");
template.opsForHash().put("redisHash","age",26);
template.opsForHash().put("redisHash","class","6");System.out.println(template.opsForHash().entries("redisHash"));结果:{age=26, class=6, name=tom}12345
使用:System.out.println(template.opsForHash().putIfAbsent("redisHash","age",30));System.out.println(template.opsForHash().putIfAbsent("redisHash","kkk","kkk"));结果:falsetrue1234
使用:System.out.println(template.opsForHash().values("redisHash"));结果:[tom, 26, 6]12
Map<HK, HV> entries(H key);
获取整个哈希存储根据**
使用:System.out.println(template.opsForHash().entries("redisHash"));结果:{age=26, class=6, name=tom}12
使用:Cursor<Map.Entry<Object, Object>> curosr = template.opsForHash().scan("redisHash", ScanOptions.ScanOptions.NONE);
while(curosr.hasNext()){
Map.Entry<Object, Object> entry = curosr.next();
System.out.println(entry.getKey()+":"+entry.getValue());
}结果:age:28.1class:6kkk:kkk12345678
Redis的Set数据结构
Redis的Set是string类型的无序集合。集合成员是唯一的,这就意味着集合中不能出现重复的数据。
Redis 中 集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是O(1)。
public interface SetOperations<K,V>
SetOperations提供了对无序集合的一系列操作:
-
Long add(K key, V… values);
无序集合中添加元素,返回添加个数
也可以直接在add里面添加多个值 如:template.opsForSet().add(“setTest”,“aaa”,“bbb”)
使用:String[] strarrays = new String[]{"strarr1","sgtarr2"};
System.out.println(template.opsForSet().add("setTest", strarrays));结果:2123
使用:String[] strarrays = new String[]{"strarr1","sgtarr2"};System.out.println(template.opsForSet().remove("setTest",strarrays));结果:2123
使用:System.out.println(template.opsForSet().pop("setTest"));System.out.println(template.opsForSet().members("setTest"));结果:bbb[aaa, ccc]1234
使用:template.opsForSet().move("setTest","aaa","setTest2");
System.out.println(template.opsForSet().members("setTest"));
System.out.println(template.opsForSet().members("setTest2"));结果:[ccc][aaa]12345
使用:System.out.println(template.opsForSet().size("setTest"));结果:112
使用:System.out.println(template.opsForSet().isMember("setTest","ccc"));
System.out.println(template.opsForSet().isMember("setTest","asd"));结果:truefalse1234
使用:System.out.println(template.opsForSet().members("setTest"));
System.out.println(template.opsForSet().members("setTest2"));
System.out.println(template.opsForSet().intersect("setTest","setTest2"));结果:[aaa, ccc][aaa][aaa]123456
使用:System.out.println(template.opsForSet().members("setTest"));
System.out.println(template.opsForSet().members("setTest2"));
System.out.println(template.opsForSet().members("setTest3"));
List<String> strlist = new ArrayList<String>();
strlist.add("setTest2");
strlist.add("setTest3");
System.out.println(template.opsForSet().intersect("setTest",strlist));结果:[aaa, ccc][aaa][ccc, aaa][aaa]1234567891011
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));System.out.println("setTest2:" + template.opsForSet().members("setTest2"));System.out.println(template.opsForSet().intersectAndStore("setTest","setTest2","destKey1"));System.out.println(template.opsForSet().members("destKey1"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]2[aaa, ccc]12345678
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println("setTest3:" + template.opsForSet().members("setTest3"));
List<String> strlist = new ArrayList<String>();
strlist.add("setTest2");
strlist.add("setTest3");
System.out.println(template.opsForSet().intersectAndStore("setTest",strlist,"destKey2"));
System.out.println(template.opsForSet().members("destKey2"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]setTest3:[ccc, aaa]2[aaa, ccc]12345678910111213
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println(template.opsForSet().union("setTest","setTest2"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa][ccc, aaa, ddd, bbb]123456
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println("setTest3:" + template.opsForSet().members("setTest3"));
List<String> strlist = new ArrayList<String>();
strlist.add("setTest2");
strlist.add("setTest3");
System.out.println(template.opsForSet().union("setTest",strlist));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]setTest3:[xxx, ccc, aaa][ddd, xxx, bbb, aaa, ccc]1234567891011
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println(template.opsForSet().unionAndStore("setTest","setTest2","unionAndStoreTest1"));
System.out.println("unionAndStoreTest1:" + template.opsForSet().members("unionAndStoreTest1"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]4unionAndStoreTest1:[ccc, aaa, ddd, bbb]12345678
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println("setTest3:" + template.opsForSet().members("setTest3"));
List<String> strlist = new ArrayList<String>();
strlist.add("setTest2");
strlist.add("setTest3");
System.out.println(template.opsForSet().unionAndStore("setTest",strlist,"unionAndStoreTest2"));
System.out.println("unionAndStoreTest2:" + template.opsForSet().members("unionAndStoreTest2"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]setTest3:[xxx, ccc, aaa]5unionAndStoreTest2:[ddd, xxx, bbb, aaa, ccc]12345678910111213
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println(template.opsForSet().difference("setTest","setTest2"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa][bbb, ddd]123456
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println("setTest3:" + template.opsForSet().members("setTest3"));
List<String> strlist = new ArrayList<String>();
strlist.add("setTest2");
strlist.add("setTest3");
System.out.println(template.opsForSet().difference("setTest",strlist));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]setTest3:[xxx, ccc, aaa][bbb, ddd]1234567891011
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println(template.opsForSet().differenceAndStore("setTest","setTest2","differenceAndStore1"));
System.out.println("differenceAndStore1:" + template.opsForSet().members("differenceAndStore1"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]2differenceAndStore1:[bbb, ddd]12345678
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTest2:" + template.opsForSet().members("setTest2"));
System.out.println("setTest3:" + template.opsForSet().members("setTest3"));
List<String> strlist = new ArrayList<String>();
strlist.add("setTest2");
strlist.add("setTest3");
System.out.println(template.opsForSet().differenceAndStore("setTest",strlist,"differenceAndStore2"));
System.out.println("differenceAndStore2:" + template.opsForSet().members("differenceAndStore2"));结果:setTest:[ddd, bbb, aaa, ccc]setTest2:[ccc, aaa]setTest3:[xxx, ccc, aaa]2differenceAndStore2:[bbb, ddd]12345678910111213
使用:System.out.println(template.opsForSet().members("setTest"));结果:[ddd, bbb, aaa, ccc]12
使用:System.out.println("setTest:" + template.opsForSet().members("setTest"));
System.out.println("setTestrandomMember:" + template.opsForSet().randomMember("setTest"));
System.out.println("setTestrandomMember:" + template.opsForSet().randomMember("setTest"));
System.out.println("setTestrandomMember:" + template.opsForSet().randomMember("setTest"));
System.out.println("setTestrandomMember:" + template.opsForSet().randomMember("setTest"));结果:setTest:[ddd, bbb, aaa, ccc]setTestrandomMember:aaa
setTestrandomMember:bbb
setTestrandomMember:aaa
setTestrandomMember:ddd12345678910
使用:System.out.println("randomMembers:" + template.opsForSet().distinctRandomMembers("setTest",5));结果:randomMembers:[aaa, bbb, ddd, ccc]12
使用:System.out.println("randomMembers:" + template.opsForSet().randomMembers("setTest",5));结果:randomMembers:[ccc, ddd, ddd, ddd, aaa]12
使用: Cursor<Object> curosr = template.opsForSet().scan("setTest", ScanOptions.NONE);
while(curosr.hasNext()){
System.out.println(curosr.next());
}结果:ddd
bbb
aaa
ccc12345678
Redis的ZSet数据结构
Redis 有序集合和无序集合一样也是string类型元素的集合,且不允许重复的成员。
不同的是每个元素都会关联一个double类型的分数。redis正是通过分数来为集合中的成员进行从小到大的排序。
有序集合的成员是唯一的,但分数(score)却可以重复。
public interface ZSetOperations<K,V>
ZSetOperations提供了一系列方法对有序集合进行操作:
使用:System.out.println(template.opsForZSet().add("zset1","zset-1",1.0));结果:true12
使用:ZSetOperations.TypedTuple<Object> objectTypedTuple1 = new DefaultTypedTuple<Object>("zset-5",9.6);
ZSetOperations.TypedTuple<Object> objectTypedTuple2 = new DefaultTypedTuple<Object>("zset-6",9.9);
Set<ZSetOperations.TypedTuple<Object>> tuples = new HashSet<ZSetOperations.TypedTuple<Object>>();
tuples.add(objectTypedTuple1);
tuples.add(objectTypedTuple2);
System.out.println(template.opsForZSet().add("zset1",tuples));
System.out.println(template.opsForZSet().range("zset1",0,-1));结果:[zset-1, zset-2, zset-3, zset-4, zset-5, zset-6]12345678
使用:System.out.println(template.opsForZSet().range("zset1",0,-1));
System.out.println(template.opsForZSet().remove("zset1","zset-6"));
System.out.println(template.opsForZSet().range("zset1",0,-1));结果:[zset-1, zset-2, zset-3, zset-4, zset-5, zset-6]1[zset-1, zset-2, zset-3, zset-4, zset-5]123456
使用:System.out.println(template.opsForZSet().incrementScore("zset1","zset-1",1.1)); //原为1.1结果:2.212
使用:System.out.println(template.opsForZSet().range("zset1",0,-1));
System.out.println(template.opsForZSet().rank("zset1","zset-2"));结果:[zset-2, zset-1, zset-3, zset-4, zset-5]0 //表明排名第一1234
使用:System.out.println(template.opsForZSet().range("zset1",0,-1));
System.out.println(template.opsForZSet().reverseRank("zset1","zset-2"));结果:[zset-2, zset-1, zset-3, zset-4, zset-5]4 //递减之后排到第五位去了1234
使用:System.out.println(template.opsForZSet().range("zset1",0,-1));结果:[zset-2, zset-1, zset-3, zset-4, zset-5]12
使用:Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().rangeWithScores("zset1",0,-1);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-2score:1.2value:zset-1score:2.2value:zset-3score:2.3value:zset-4score:6.6value:zset-5score:9.6123456789101112
使用:System.out.println(template.opsForZSet().rangeByScore("zset1",0,5));结果:[zset-2, zset-1, zset-3]12
使用:Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().rangeByScoreWithScores("zset1",0,5);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-2score:1.2value:zset-1score:2.2value:zset-3score:2.312345678910
-
Set rangeByScore(K key, double min, double max, long offset, long count);
通过分数返回有序集合指定区间内的成员,并在索引范围内,其中有序集成员按分数值递增(从小到大)顺序排列
使用: System.out.println(template.opsForZSet().rangeByScore("zset1",0,5));
System.out.println(template.opsForZSet().rangeByScore("zset1",0,5,1,2));结果:[zset-2, zset-1, zset-3][zset-1, zset-3]1234
-
Set<TypedTuple> rangeByScoreWithScores(K key, double min, double max, long offset, long count);
通过分数返回有序集合指定区间内的成员对象,并在索引范围内,其中有序集成员按分数值递增(从小到大)顺序排列
使用:Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().rangeByScoreWithScores("zset1",0,5,1,2);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-1score:2.2value:zset-3score:2.3123456789
使用:System.out.println(template.opsForZSet().reverseRange("zset1",0,-1));结果:[zset-5, zset-4, zset-3, zset-1, zset-2]12
使用:Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().reverseRangeWithScores("zset1",0,-1);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-5score:9.6value:zset-4score:6.6value:zset-3score:2.3value:zset-1score:2.2value:zset-2score:1.2123456789101112
-
Set reverseRangeByScore(K key, double min, double max);
使用:与rangeByScore调用方法一样,其中有序集成员按分数值递减(从大到小)顺序排列
-
Set<TypedTuple> reverseRangeByScoreWithScores(K key, double min, double max);
使用:与rangeByScoreWithScores调用方法一样,其中有序集成员按分数值递减(从大到小)顺序排列
-
Set reverseRangeByScore(K key, double min, double max, long offset, long count);
使用:与rangeByScore调用方法一样,其中有序集成员按分数值递减(从大到小)顺序排列
-
Set<TypedTuple> reverseRangeByScoreWithScores(K key, double min, double max, long offset, long count);
使用:与rangeByScoreWithScores调用方法一样,其中有序集成员按分数值递减(从大到小)顺序排列
-
Long count(K key, double min, double max);
通过分数返回有序集合指定区间内的成员个数
使用:System.out.println(template.opsForZSet().rangeByScore("zset1",0,5));
System.out.println(template.opsForZSet().count("zset1",0,5));结果:[zset-2, zset-1, zset-3]31234
使用:System.out.println(template.opsForZSet().size("zset1"));结果:612
使用:System.out.println(template.opsForZSet().zCard("zset1"));结果:612
使用:System.out.println(template.opsForZSet().score("zset1","zset-1"));结果:2.212
使用:System.out.println(template.opsForZSet().range("zset2",0,-1));
System.out.println(template.opsForZSet().removeRange("zset2",1,2));
System.out.println(template.opsForZSet().range("zset2",0,-1));结果:[zset-1, zset-2, zset-3, zset-4]2[zset-1, zset-4]123456
使用://System.out.println(template.opsForZSet().add("zset2","zset-1",1.1));
//System.out.println(template.opsForZSet().add("zset2","zset-2",1.2));
//System.out.println(template.opsForZSet().add("zset2","zset-3",2.3));
//System.out.println(template.opsForZSet().add("zset2","zset-4",6.6));System.out.println(template.opsForZSet().range("zset2",0,-1));System.out.println(template.opsForZSet().removeRangeByScore("zset2",2,3));
System.out.println(template.opsForZSet().range("zset2",0,-1));结果:[zset-1, zset-2, zset-3,zset-4]1[zset-1, zset-2, zset-4]12345678910
使用:System.out.println(template.opsForZSet().add("zzset1","zset-1",1.0));
System.out.println(template.opsForZSet().add("zzset1","zset-2",2.0));
System.out.println(template.opsForZSet().add("zzset1","zset-3",3.0));
System.out.println(template.opsForZSet().add("zzset1","zset-4",6.0));
System.out.println(template.opsForZSet().add("zzset2","zset-1",1.0));
System.out.println(template.opsForZSet().add("zzset2","zset-2",2.0));
System.out.println(template.opsForZSet().add("zzset2","zset-3",3.0));
System.out.println(template.opsForZSet().add("zzset2","zset-4",6.0));
System.out.println(template.opsForZSet().add("zzset2","zset-5",7.0));
System.out.println(template.opsForZSet().unionAndStore("zzset1","zzset2","destZset11"));
Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().rangeWithScores("destZset11",0,-1);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-1score:2.0value:zset-2score:4.0value:zset-3score:6.0value:zset-5score:7.0value:zset-4score:12.0123456789101112131415161718192021222324
使用://System.out.println(template.opsForZSet().add("zzset1","zset-1",1.0));
//System.out.println(template.opsForZSet().add("zzset1","zset-2",2.0));
//System.out.println(template.opsForZSet().add("zzset1","zset-3",3.0));
//System.out.println(template.opsForZSet().add("zzset1","zset-4",6.0));
//
//System.out.println(template.opsForZSet().add("zzset2","zset-1",1.0));
//System.out.println(template.opsForZSet().add("zzset2","zset-2",2.0));
//System.out.println(template.opsForZSet().add("zzset2","zset-3",3.0));
//System.out.println(template.opsForZSet().add("zzset2","zset-4",6.0));
//System.out.println(template.opsForZSet().add("zzset2","zset-5",7.0));
System.out.println(template.opsForZSet().add("zzset3","zset-1",1.0));
System.out.println(template.opsForZSet().add("zzset3","zset-2",2.0));
System.out.println(template.opsForZSet().add("zzset3","zset-3",3.0));
System.out.println(template.opsForZSet().add("zzset3","zset-4",6.0));
System.out.println(template.opsForZSet().add("zzset3","zset-5",7.0));
List<String> stringList = new ArrayList<String>();
stringList.add("zzset2");
stringList.add("zzset3");
System.out.println(template.opsForZSet().unionAndStore("zzset1",stringList,"destZset22"));
Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().rangeWithScores("destZset22",0,-1);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-1score:3.0value:zset-2score:6.0value:zset-3score:9.0value:zset-5score:14.0value:zset-4score:18.012345678910111213141516171819202122232425262728293031323334
使用:System.out.println(template.opsForZSet().intersectAndStore("zzset1","zzset2","destZset33"));
Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().rangeWithScores("destZset33",0,-1);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-1score:2.0value:zset-2score:4.0value:zset-3score:6.0value:zset-4score:12.012345678910111213
使用:List<String> stringList = new ArrayList<String>();
stringList.add("zzset2");
stringList.add("zzset3");
System.out.println(template.opsForZSet().intersectAndStore("zzset1",stringList,"destZset44"));
Set<ZSetOperations.TypedTuple<Object>> tuples = template.opsForZSet().rangeWithScores("destZset44",0,-1);
Iterator<ZSetOperations.TypedTuple<Object>> iterator = tuples.iterator();
while (iterator.hasNext())
{
ZSetOperations.TypedTuple<Object> typedTuple = iterator.next();
System.out.println("value:" + typedTuple.getValue() + "score:" + typedTuple.getScore());
}结果:value:zset-1score:3.0value:zset-2score:6.0value:zset-3score:9.0value:zset-4score:18.012345678910111213141516
使用: Cursor<ZSetOperations.TypedTuple<Object>> cursor = template.opsForZSet().scan("zzset1", ScanOptions.NONE);
while (cursor.hasNext()){
ZSetOperations.TypedTuple<Object> item = cursor.next();
System.out.println(item.getValue() + ":" + item.getScore());
}结果:zset-1:1.0zset-2:2.0zset-3:3.0zset-4:6.0123456789
注:TimeUnit是java.util.concurrent包下面的一个类,表示给定单元粒度的时间段
常用的颗粒度
TimeUnit.DAYS //天
TimeUnit.HOURS //小时
TimeUnit.MINUTES //分钟
TimeUnit.SECONDS //秒
TimeUnit.MILLISECONDS //毫秒
转自:https://www.jianshu.com/p/7bf5dc61ca06