zSet的key中添加一条缓存
public boolean zAdd(String key, Object value, double score) {
try {
return redisTemplate.opsForZSet().add(key, value, score);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
zSet的key中添加多条缓存
**
public long zAdd(String key, Set<ZSetOperations.TypedTuple<Object>> values) {
try {
return redisTemplate.opsForZSet().add(key, values);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}**
获取key的元素数量
public long zCard(String key) {
try {
return redisTemplate.opsForZSet().size(key);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
获取key中分值在某一区间的值的个数
public long zCount(String key, double scoreMin, double scoreMax) {
try {
return redisTemplate.opsForZSet().count(key, scoreMin, scoreMax);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
给key中的value元素分值增加delta
public double zIncrBy(String key, String value, double delta) {
try {
return redisTemplate.opsForZSet().incrementScore(key, value, delta);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
key与otherKey的交集存储至destKey中
public long zInterStore(String key, String destKey, String... otherKeys) {
try {
return redisTemplate.opsForZSet()
.intersectAndStore(key, (Collection<String>) CollectionUtils.arrayToList(otherKeys), destKey);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
按索引返回一组元素集合
public Set<Object> zRange(String key, long start, long end) {
try {
return redisTemplate.opsForZSet().range(key, start, end);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
withScores 按索引返回一组带元素分值的元素集合
public Set<ZSetOperations.TypedTuple<Object>> rangeWithScores(String key, long start, long end) {
try {
return redisTemplate.opsForZSet().rangeWithScores(key, start, end);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
按分值排序返回一组元素集合
public Set<Object> zRangeByScore(String key, double minScore, double maxScore) {
try {
return redisTemplate.opsForZSet().rangeByScore(key, minScore, maxScore);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
withScore 按分值排序返回一组带分值的元素的集合
public Set<ZSetOperations.TypedTuple<Object>> zRangeByScoreWithsScore(
String key, double minScore, double maxScore) {
try {
return redisTemplate.opsForZSet().rangeByScoreWithScores(key, minScore, maxScore);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
按分值排序(倒序)返回一组元素集合
public Set<Object> zReverseRangeByScore(String key, double minScore, double maxScore) {
try {
return redisTemplate.opsForZSet().reverseRangeByScore(key, minScore, maxScore);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
withScore 按分值排序(倒序)返回一组带分值的元素的集合
public Set<ZSetOperations.TypedTuple<Object>> zRevAngeByScoreWithScore(
String key, double minScore, double maxScore) {
try {
return redisTemplate.opsForZSet().reverseRangeByScoreWithScores(key, minScore, maxScore);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
删除一个或多个值
public long zRem(String key, Object... values) {
try {
return redisTemplate.opsForZSet().remove(key, values);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
获取zSet中value的升序排名
public long zRank(String key, Object value) {
try {
return redisTemplate.opsForZSet().rank(key, value);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
获取zSet中value的降序排名
public long zRevRank(String key, Object value) {
try {
return redisTemplate.opsForZSet().reverseRank(key, value);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
获取zSet中value的分值
public double zScore(String key, Object value) {
try {
return redisTemplate.opsForZSet().score(key, value);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
两个zSet的并集插入到destKey的zSet中
public long zUnionStore(String key, String destKey, String... otherKeys) {
try {
return redisTemplate.opsForZSet()
.unionAndStore(key, (Collection<String>) CollectionUtils.arrayToList(otherKeys), destKey);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
两个zSet的并集插入到destKey的zSet中
public long zUnionStore(String key, String destKey, List<String> otherKeysList) {
try {
return redisTemplate.opsForZSet()
.unionAndStore(key, otherKeysList, destKey);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
从高到低的排序集中获取从头(start)到尾(end)内的元素。
public Set<ZSetOperations.TypedTuple<Object>> zReverseRangeWithScores(String key, long start, long end) {
try {
return redisTemplate.opsForZSet().reverseRangeWithScores(key, start, end);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}