当前位置:   article > 正文

RedisTemplate-opsForZSet集合有分数-api_redistemplate.opsforzset().reverserange

redistemplate.opsforzset().reverserange
  1. 1add(K key, V value, double score)
  2. 添加元素到变量中同时指定元素的分值。
  3. redisTemplate.opsForZSet().add("zSetValue","A",1);
  4. redisTemplate.opsForZSet().add("zSetValue","B",3);
  5. redisTemplate.opsForZSet().add("zSetValue","C",2);
  6. redisTemplate.opsForZSet().add("zSetValue","D",5);
  7. 2、range(K key, long start, long end)
  8. 获取变量指定区间的元素。
  9. Set zSetValue = redisTemplate.opsForZSet().range("zSetValue",0,-1);
  10. System.out.println("指定区间的元素:" + zSetValue);
  11. 3、rangeByLex(K key, RedisZSetCommands.Range range)
  12. 用于获取满足非score的排序取值。这个排序只有在有相同分数的情况下才能使用,如果有不同的分数则返回值不确定。
  13. RedisZSetCommands.Range range = new RedisZSetCommands.Range();
  14. //range.gt("A");
  15. range.lt("D");
  16. zSetValue = redisTemplate.opsForZSet().rangeByLex("zSetValue", range);
  17. System.out.println("获取满足非score的排序取值元素:" + zSetValue);
  18. 4、rangeByLex(K key, RedisZSetCommands.Range range, RedisZSetCommands.Limit limit)
  19. 用于获取满足非score的设置下标开始的长度排序取值。
  20. RedisZSetCommands.Limit limit = new RedisZSetCommands.Limit();
  21. limit.count(2);
  22. //起始下标为0
  23. limit.offset(1);
  24. zSetValue = redisTemplate.opsForZSet().rangeByLex("zSetValue", range,limit);
  25. System.out.println("满足非score的排序取值元素:" + zSetValue);
  26. 5add(K key, Set<ZSetOperations.TypedTuple<V>> tuples)
  27. 通过TypedTuple方式新增数据。
  28. ZSetOperations.TypedTuple<String> typedTuple1 = new DefaultTypedTuple<String>("E",6.0);
  29. ZSetOperations.TypedTuple<String> typedTuple2 = new DefaultTypedTuple<String>("F",7.0);
  30. ZSetOperations.TypedTuple<String> typedTuple3 = new DefaultTypedTuple<String>("G",5.0);
  31. Set<ZSetOperations.TypedTuple<String>> typedTupleSet = new HashSet<ZSetOperations.TypedTuple<String>>();
  32. typedTupleSet.add(typedTuple1);
  33. typedTupleSet.add(typedTuple2);
  34. typedTupleSet.add(typedTuple3);
  35. redisTemplate.opsForZSet().add("typedTupleSet",typedTupleSet);
  36. zSetValue = redisTemplate.opsForZSet().range("typedTupleSet",0,-1);
  37. System.out.println("添加元素:" + zSetValue);
  38. 6、rangeByScore(K key, double min, double max)
  39. 根据设置的score获取区间值。
  40. zSetValue = redisTemplate.opsForZSet().rangeByScore("zSetValue",1,2);
  41. System.out.println("区间值:" + zSetValue);
  42. 7、rangeByScore(K key, double min, double max,long offset, long count)
  43. 根据设置的score获取区间值从给定下标和给定长度获取最终值。
  44. zSetValue = redisTemplate.opsForZSet().rangeByScore("zSetValue",1,5,1,3);
  45. System.out.println("根据设置的score获取区间值:" + zSetValue);
  46. 8、rangeWithScores(K key, long start, long end)
  47. 获取RedisZSetCommands.Tuples的区间值。
  48. Set<ZSetOperations.TypedTuple<String>> typedTupleSet = redisTemplate.opsForZSet().rangeWithScores("typedTupleSet",1,3);
  49. Iterator<ZSetOperations.TypedTuple<String>> iterator = typedTupleSet.iterator();
  50. while (iterator.hasNext()){
  51. ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
  52. Object value = typedTuple.getValue();
  53. double score = typedTuple.getScore();
  54. System.out.println("获取RedisZSetCommands.Tuples的区间值:" + value + "---->" + score );
  55. }
  56. 9、rangeByScoreWithScores(K key, double min, double max)
  57. 获取RedisZSetCommands.Tuples的区间值通过分值。
  58. Set<ZSetOperations.TypedTuple<String>> typedTupleSet = redisTemplate.opsForZSet().rangeByScoreWithScores("typedTupleSet",5,8);
  59. iterator = typedTupleSet.iterator();
  60. while (iterator.hasNext()){
  61. ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
  62. Object value = typedTuple.getValue();
  63. double score = typedTuple.getScore();
  64. System.out.println("区间值通过分值:" + value + "---->" + score );
  65. }
  66. 10、rangeByScoreWithScores(K key, double min, double max, long offset, long count)
  67. 获取RedisZSetCommands.Tuples的区间值从给定下标和给定长度获取最终值通过分值。
  68. Set<ZSetOperations.TypedTuple<String>> typedTupleSet = redisTemplate.opsForZSet().rangeByScoreWithScores("typedTupleSet",5,8,1,1);
  69. iterator = typedTupleSet.iterator();
  70. while (iterator.hasNext()){
  71. ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
  72. Object value = typedTuple.getValue();
  73. double score = typedTuple.getScore();
  74. System.out.println("通过分值:" + value + "---->" + score );
  75. }
  76. 11count(K key, double min, double max)
  77. 获取区间值的个数。
  78. long count = redisTemplate.opsForZSet().count("zSetValue",1,5);
  79. System.out.println("个数:" + count);
  80. 12、rank(K key, Object o)
  81. 获取变量中元素的索引,下标开始位置为0
  82. long index = redisTemplate.opsForZSet().rank("zSetValue","B");
  83. System.out.println("获取变量中元素的索引:" + index);
  84. 13、scan(K key, ScanOptions options)
  85. 匹配获取键值对,ScanOptions.NONE为获取全部键值对;ScanOptions.scanOptions().match("C").build()匹配获取键位map1的键值对,不能模糊匹配。
  86. //Cursor<String> cursor = redisTemplate.opsForSet().scan("setValue", ScanOptions.NONE);
  87. Cursor<ZSetOperations.TypedTuple<String>> cursor = redisTemplate.opsForZSet().scan("zSetValue", ScanOptions.NONE);
  88. while (cursor.hasNext()){
  89. ZSetOperations.TypedTuple<String> typedTuple = cursor.next();
  90. System.out.println("元素:" + typedTuple.getValue() + "--->" + typedTuple.getScore());
  91. }
  92. 14、score(K key, Object o)
  93. 获取元素的分值。
  94. double score = redisTemplate.opsForZSet().score("zSetValue","B");
  95. System.out.println("元素的分值:" + score);
  96. 15、zCard(K key)
  97. 获取变量中元素的个数。
  98. long zCard = redisTemplate.opsForZSet().zCard("zSetValue");
  99. System.out.println("变量的长度:" + zCard);
  100. 16、incrementScore(K key, V value, double delta)
  101. 修改变量中的元素的分值。
  102. double incrementScore = redisTemplate.opsForZSet().incrementScore("zSetValue","C",5);
  103. System.out.print("通过incrementScore(K key, V value, double delta)方法修改变量中的元素的分值:" + incrementScore);
  104. score = redisTemplate.opsForZSet().score("zSetValue","C");
  105. System.out.print(",修改后获取元素的分值:" + score);
  106. zSetValue = redisTemplate.opsForZSet().range("zSetValue",0,-1);
  107. System.out.println(",修改后排序的元素:" + zSetValue);
  108. 17、reverseRange(K key, long start, long end)
  109. 索引倒序排列指定区间元素。
  110. zSetValue = redisTemplate.opsForZSet().reverseRange("zSetValue",0,-1);
  111. System.out.println("倒序排列元素:" + zSetValue);
  112. 18、reverseRangeByScore(K key, double min, double max)
  113. 倒序排列指定分值区间元素。
  114. zSetValue = redisTemplate.opsForZSet().reverseRangeByScore("zSetValue",1,5);
  115. System.out.println("元素:" + zSetValue);
  116. 19、reverseRangeByScore(K key, double min, double max, long offset, long count)
  117. 倒序排列从给定下标和给定长度分值区间元素。
  118. zSetValue = redisTemplate.opsForZSet().reverseRangeByScore("zSetValue",1,5,1,2);
  119. System.out.println("区间元素:" + zSetValue);
  120. 20、reverseRangeByScoreWithScores(K key, double min, double max)
  121. 倒序排序获取RedisZSetCommands.Tuples的分值区间值。
  122. Set<ZSetOperations.TypedTuple<String>> typedTupleSet = redisTemplate.opsForZSet().reverseRangeByScoreWithScores("zSetValue",1,5);
  123. iterator = typedTupleSet.iterator();
  124. while (iterator.hasNext()){
  125. ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
  126. Object value = typedTuple.getValue();
  127. double score1 = typedTuple.getScore();
  128. System.out.println("区间值:" + value + "---->" + score1 );
  129. }
  130. 21、reverseRangeByScoreWithScores(K key, double min, double max, long offset, long count)
  131. 倒序排序获取RedisZSetCommands.Tuples的从给定下标和给定长度分值区间值。
  132. Set<ZSetOperations.TypedTuple<String>> typedTupleSet = redisTemplate.opsForZSet().reverseRangeByScoreWithScores("zSetValue",1,5,1,2);
  133. iterator = typedTupleSet.iterator();
  134. while (iterator.hasNext()){
  135. ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
  136. Object value = typedTuple.getValue();
  137. double score1 = typedTuple.getScore();
  138. System.out.println("区间值:" + value + "---->" + score1 );
  139. }
  140. 22、reverseRangeWithScores(K key, long start, long end)
  141. 索引倒序排列区间值。
  142. Set<ZSetOperations.TypedTuple<String>> typedTupleSet = redisTemplate.opsForZSet().reverseRangeWithScores("zSetValue",1,5);
  143. iterator = typedTupleSet.iterator();
  144. while (iterator.hasNext()){
  145. ZSetOperations.TypedTuple<String> typedTuple = iterator.next();
  146. Object value = typedTuple.getValue();
  147. double score1 = typedTuple.getScore();
  148. System.out.println("区间值:" + value + "----->" + score1);
  149. }
  150. 23、reverseRank(K key, Object o)
  151. 获取倒序排列的索引值。
  152. long reverseRank = redisTemplate.opsForZSet().reverseRank("zSetValue","B");
  153. System.out.println("索引值:" + reverseRank);
  154. 24、intersectAndStore(K key, K otherKey, K destKey)
  155. 获取2个变量的交集存放到第3个变量里面。
  156. redisTemplate.opsForZSet().intersectAndStore("zSetValue","typedTupleSet","intersectSet");
  157. zSetValue = redisTemplate.opsForZSet().range("intersectSet",0,-1);
  158. System.out.println("里面:" + zSetValue);
  159. 25、intersectAndStore(K key, Collection<K> otherKeys, K destKey)
  160. 获取多个变量的交集存放到第3个变量里面。
  161. List list = new ArrayList();
  162. list.add("typedTupleSet");
  163. redisTemplate.opsForZSet().intersectAndStore("zSetValue",list,"intersectListSet");
  164. zSetValue = redisTemplate.opsForZSet().range("intersectListSet",0,-1);
  165. System.out.println("里面:" + zSetValue);
  166. 26、unionAndStore(K key, K otherKey, K destKey)
  167. 获取2个变量的合集存放到第3个变量里面。
  168. redisTemplate.opsForZSet().unionAndStore("zSetValue","typedTupleSet","unionSet");
  169. zSetValue = redisTemplate.opsForZSet().range("unionSet",0,-1);
  170. System.out.println("里面:" + zSetValue);
  171. 27、unionAndStore(K key, Collection<K> otherKeys, K destKey)
  172. 获取多个变量的合集存放到第3个变量里面。
  173. redisTemplate.opsForZSet().unionAndStore("zSetValue",list,"unionListSet");
  174. zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
  175. System.out.println("里面:" + zSetValue);
  176. 28、remove(K key, Object... values)
  177. 批量移除元素根据元素值。
  178. long removeCount = redisTemplate.opsForZSet().remove("unionListSet","A","B");
  179. zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
  180. System.out.print("移除元素的个数:" + removeCount);
  181. System.out.println(",移除后剩余的元素:" + zSetValue);
  182. 29、removeRangeByScore(K key, double min, double max)
  183. 根据分值移除区间元素。
  184. removeCount = redisTemplate.opsForZSet().removeRangeByScore("unionListSet",3,5);
  185. zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
  186. System.out.print("移除元素的个数:" + removeCount);
  187. System.out.println(",移除后剩余的元素:" + zSetValue);
  188. 30、removeRange(K key, long start, long end)
  189. 根据索引值移除区间元素。
  190. removeCount = redisTemplate.opsForZSet().removeRange("unionListSet",3,5);
  191. zSetValue = redisTemplate.opsForZSet().range("unionListSet",0,-1);
  192. System.out.print("移除元素的个数:" + removeCount);
  193. System.out.println(",移除后剩余的元素:" + zSetValue);

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/886437
推荐阅读
相关标签
  

闽ICP备14008679号