0
点赞
收藏
分享

微信扫一扫

jedis高级用法

1、有序集合开区间



1、redis命令 ZRANGEBYSCORE key min max [WITHSCORES][LIMIT offset count]

  • 根据score区间获取集合中的元素,可选项[WITHSCORES]表示选出的元素是否带score值;
  • 可选项[LIMIT offset count]表示分页获取数据;
  • 该命令默认是使用闭区间(包含min max),也可以通过给参数前增加 ( 符号来使用可选的开区间 (小于或大于);例如:

ZRANGEBYSCOREzset (1 5

 

补充:ZCOUNT key minmax 命令,同样可以使用区间的开闭;

 

2、使用jedis客户端,可以使用区间的开闭控制:

String minScore ="("+time;

String maxScore =currentTime+"";

Long zcount =ShelfRedisUtils.zcount(shelfCustomerKey, minScore, maxScore);

Set<Tuple>shelfDatasSet = ShelfRedisUtils.zrangebyscoreWithScores(shelfCustomerKey,minScore, maxScore, 0, pageSize);


2、批量操作:


Get the values ofall the specified keys. If one or more keys dont exist or is not of typeString, a 'nil' value is returned instead of the value of the specified key,but the operation never fails.


public List<String> mget(String[] keys) {
Jedis jedis = borrow();
try {
return jedis.mget(keys);
} finally {
revert(jedis);
}
}

byte[][] bkeys = new byte[len][];
for (int i = 0; i < keys.length; i++) {
bkeys[i] = keys[i].getBytes();
}
try {
List<byte[]> list = jedis.mget(bkeys);
List<String> temp_list = new ArrayList<String>(list.size());
for (byte[] temp : list) {
temp_list.add(GZip.decodeWithGZip(temp));
}
return temp_list;




举报

相关推荐

0 条评论