packagecom.citydo.utils;importorg.springframework.data.redis.connection.DataType;importorg.springframework.data.redis.core.Cursor;importorg.springframework.data.redis.core.ScanOptions;importorg.springframework.data.redis.core.StringRedisTemplate;importorg.springframework.data.redis.core.ZSetOperations.TypedTuple;importjava.util.Collection;importjava.util.Date;importjava.util.List;importjava.util.Map;importjava.util.Map.Entry;importjava.util.Set;importjava.util.concurrent.TimeUnit;/*** Redis工具类*/
public classRedisUtil {privateStringRedisTemplate redisTemplate;public voidsetRedisTemplate(StringRedisTemplate redisTemplate) {this.redisTemplate =redisTemplate;
}publicStringRedisTemplate getRedisTemplate() {return this.redisTemplate;
}/**-------------------key相关操作---------------------*/
/*** 删除key
*
*@paramkey*/
public voiddelete(String key) {
redisTemplate.delete(key);
}/*** 批量删除key
*
*@paramkeys*/
public void delete(Collectionkeys) {
redisTemplate.delete(keys);
}/*** 序列化key
*
*@paramkey
*@return
*/
public byte[] dump(String key) {returnredisTemplate.dump(key);
}/*** 是否存在key
*
*@paramkey
*@return
*/
publicBoolean hasKey(String key) {returnredisTemplate.hasKey(key);
}/*** 设置过期时间
*
*@paramkey
*@paramtimeout
*@paramunit
*@return
*/
public Boolean expire(String key, longtimeout, TimeUnit unit) {returnredisTemplate.expire(key, timeout, unit);
}/*** 设置过期时间
*
*@paramkey
*@paramdate
*@return
*/
publicBoolean expireAt(String key, Date date) {returnredisTemplate.expireAt(key, date);
}/*** 查找匹配的key
*
*@parampattern
*@return
*/
public Setkeys(String pattern) {returnredisTemplate.keys(pattern);
}/*** 将当前数据库的 key 移动到给定的数据库 db 当中
*
*@paramkey
*@paramdbIndex
*@return
*/
public Boolean move(String key, intdbIndex) {returnredisTemplate.move(key, dbIndex);
}/*** 移除 key 的过期时间,key 将持久保持
*
*@paramkey
*@return
*/
publicBoolean persist(String key) {returnredisTemplate.persist(key);
}/*** 返回 key 的剩余的过期时间
*
*@paramkey
*@paramunit
*@return
*/
publicLong getExpire(String key, TimeUnit unit) {returnredisTemplate.getExpire(key, unit);
}/*** 返回 key 的剩余的过期时间
*
*@paramkey
*@return
*/
publicLong getExpire(String key) {returnredisTemplate.getExpire(key);
}/*** 从当前数据库中随机返回一个 key
*
*@return
*/
publicString randomKey() {returnredisTemplate.randomKey();
}/*** 修改 key 的名称
*
*@paramoldKey
*@paramnewKey*/
public voidrename(String oldKey, String newKey) {
redisTemplate.rename(oldKey, newKey);
}/*** 仅当 newkey 不存在时,将 oldKey 改名为 newkey
*
*@paramoldKey
*@paramnewKey
*@return
*/
publicBoolean renameIfAbsent(String oldKey, String newKey) {returnredisTemplate.renameIfAbsent(oldKey, newKey);
}/*** 返回 key 所储存的值的类型
*
*@paramkey
*@return
*/
publicDataType type(String key) {returnredisTemplate.type(key);
}/**-------------------string相关操作---------------------*/
/*** 设置指定 key 的值
*@paramkey
*@paramvalue*/
public voidset(String key, String value) {
redisTemplate.opsForValue().set(key, value);
}/*** 获取指定 key 的值
*@paramkey
*@return
*/
publicString get(String key) {returnredisTemplate.opsForValue().get(key);
}/*** 返回 key 中字符串值的子字符
*@paramkey
*@paramstart
*@paramend
*@return
*/
public String getRange(String key, long start, longend) {returnredisTemplate.opsForValue().get(key, start, end);
}/*** 将给定 key 的值设为 value ,并返回 key 的旧值(old value)
*
*@paramkey
*@paramvalue
*@return
*/
publicString getAndSet(String key, String value) {returnredisTemplate.opsForValue().getAndSet(key, value);
}/*** 对 key 所储存的字符串值,获取指定偏移量上的位(bit)
*
*@paramkey
*@paramoffset
*@return
*/
public Boolean getBit(String key, longoffset) {returnredisTemplate.opsForValue().getBit(key, offset);
}/*** 批量获取
*
*@paramkeys
*@return
*/
public List multiGet(Collectionkeys) {returnredisTemplate.opsForValue().multiGet(keys);
}/*** 设置ASCII码, 字符串‘a‘的ASCII码是97, 转为二进制是‘01100001‘, 此方法是将二进制第offset位值变为value
*
*@paramkey 位置
*@paramvalue
* 值,true为1, false为0
*@return
*/
public boolean setBit(String key, long offset, booleanvalue) {returnredisTemplate.opsForValue().setBit(key, offset, value);
}/*** 将值 value 关联到 key ,并将 key 的过期时间设为 timeout
*
*@paramkey
*@paramvalue
*@paramtimeout
* 过期时间
*@paramunit
* 时间单位, 天:TimeUnit.DAYS 小时:TimeUnit.HOURS 分钟:TimeUnit.MINUTES
* 秒:TimeUnit.SECONDS 毫秒:TimeUnit.MILLISECONDS*/
public void setEx(String key, String value, longtimeout, TimeUnit unit) {
redisTemplate.opsForValue().set(key, value, timeout, unit);
}/*** 只有在 key 不存在时设置 key 的值
*
*@paramkey
*@paramvalue
*@return之前已经存在返回false,不存在返回true*/
public booleansetIfAbsent(String key, String value) {returnredisTemplate.opsForValue().setIfAbsent(key, value);
}/*** 用 value 参数覆写给定 key 所储存的字符串值,从偏移量 offset 开始
*
*@paramkey
*@paramvalue
*@paramoffset
* 从指定位置开始覆写*/
public void setRange(String key, String value, longoffset) {
redisTemplate.opsForValue().set(key, value, offset);
}/*** 获取字符串的长度
*
*@paramkey
*@return
*/
publicLong size(String key) {returnredisTemplate.opsForValue().size(key);
}/*** 批量添加
*
*@parammaps*/
public void multiSet(Mapmaps) {
redisTemplate.opsForValue().multiSet(maps);
}/*** 同时设置一个或多个 key-value 对,当且仅当所有给定 key 都不存在
*
*@parammaps
*@return之前已经存在返回false,不存在返回true*/
public boolean multiSetIfAbsent(Mapmaps) {returnredisTemplate.opsForValue().multiSetIfAbsent(maps);
}/*** 增加(自增长), 负数则为自减
*
*@paramkey
*@return
*/
public Long incrBy(String key, longincrement) {returnredisTemplate.opsForValue().increment(key, increment);
}/***
*@paramkey
*@return
*/
public Double incrByFloat(String key, doubleincrement) {returnredisTemplate.opsForValue().increment(key, increment);
}/*** 追加到末尾
*
*@paramkey
*@paramvalue
*@return
*/
publicInteger append(String key, String value) {returnredisTemplate.opsForValue().append(key, value);
}/**-------------------hash相关操作-------------------------*/
/*** 获取存储在哈希表中指定字段的值
*
*@paramkey
*@paramfield
*@return
*/
publicObject hGet(String key, String field) {returnredisTemplate.opsForHash().get(key, field);
}/*** 获取所有给定字段的值
*
*@paramkey
*@return
*/
public MaphGetAll(String key) {returnredisTemplate.opsForHash().entries(key);
}/*** 获取所有给定字段的值
*
*@paramkey
*@paramfields
*@return
*/
public List hMultiGet(String key, Collectionfields) {returnredisTemplate.opsForHash().multiGet(key, fields);
}public voidhPut(String key, String hashKey, String value) {
redisTemplate.opsForHash().put(key, hashKey, value);
}public void hPutAll(String key, Mapmaps) {
redisTemplate.opsForHash().putAll(key, maps);
}/*** 仅当hashKey不存在时才设置
*
*@paramkey
*@paramhashKey
*@paramvalue
*@return
*/
publicBoolean hPutIfAbsent(String key, String hashKey, String value) {returnredisTemplate.opsForHash().putIfAbsent(key, hashKey, value);
}/*** 删除一个或多个哈希表字段
*
*@paramkey
*@paramfields
*@return
*/
publicLong hDelete(String key, Object... fields) {returnredisTemplate.opsForHash().delete(key, fields);
}/*** 查看哈希表 key 中,指定的字段是否存在
*
*@paramkey
*@paramfield
*@return
*/
public booleanhExists(String key, String field) {returnredisTemplate.opsForHash().hasKey(key, field);
}/*** 为哈希表 key 中的指定字段的整数值加上增量 increment
*
*@paramkey
*@paramfield
*@paramincrement
*@return
*/
public Long hIncrBy(String key, Object field, longincrement) {returnredisTemplate.opsForHash().increment(key, field, increment);
}/*** 为哈希表 key 中的指定字段的整数值加上增量 increment
*
*@paramkey
*@paramfield
*@paramdelta
*@return
*/
public Double hIncrByFloat(String key, Object field, doubledelta) {returnredisTemplate.opsForHash().increment(key, field, delta);
}/*** 获取所有哈希表中的字段
*
*@paramkey
*@return
*/
public SethKeys(String key) {returnredisTemplate.opsForHash().keys(key);
}/*** 获取哈希表中字段的数量
*
*@paramkey
*@return
*/
publicLong hSize(String key) {returnredisTemplate.opsForHash().size(key);
}/*** 获取哈希表中所有值
*
*@paramkey
*@return
*/
public ListhValues(String key) {returnredisTemplate.opsForHash().values(key);
}/*** 迭代哈希表中的键值对
*
*@paramkey
*@paramoptions
*@return
*/
public Cursor>hScan(String key, ScanOptions options) {returnredisTemplate.opsForHash().scan(key, options);
}/**------------------------list相关操作----------------------------*/
/*** 通过索引获取列表中的元素
*
*@paramkey
*@paramindex
*@return
*/
public String lIndex(String key, longindex) {returnredisTemplate.opsForList().index(key, index);
}/*** 获取列表指定范围内的元素
*
*@paramkey
*@paramstart
* 开始位置, 0是开始位置
*@paramend
* 结束位置, -1返回所有
*@return
*/
public List lRange(String key, long start, longend) {returnredisTemplate.opsForList().range(key, start, end);
}/*** 存储在list头部
*
*@paramkey
*@paramvalue
*@return
*/
publicLong lLeftPush(String key, String value) {returnredisTemplate.opsForList().leftPush(key, value);
}/***
*@paramkey
*@paramvalue
*@return
*/
publicLong lLeftPushAll(String key, String... value) {returnredisTemplate.opsForList().leftPushAll(key, value);
}/***
*@paramkey
*@paramvalue
*@return
*/
public Long lLeftPushAll(String key, Collectionvalue) {returnredisTemplate.opsForList().leftPushAll(key, value);
}/*** 当list存在的时候才加入
*
*@paramkey
*@paramvalue
*@return
*/
publicLong lLeftPushIfPresent(String key, String value) {returnredisTemplate.opsForList().leftPushIfPresent(key, value);
}/*** 如果pivot存在,再pivot前面添加
*
*@paramkey
*@parampivot
*@paramvalue
*@return
*/
publicLong lLeftPush(String key, String pivot, String value) {returnredisTemplate.opsForList().leftPush(key, pivot, value);
}/***
*@paramkey
*@paramvalue
*@return
*/
publicLong lRightPush(String key, String value) {returnredisTemplate.opsForList().rightPush(key, value);
}/***
*@paramkey
*@paramvalue
*@return
*/
publicLong lRightPushAll(String key, String... value) {returnredisTemplate.opsForList().rightPushAll(key, value);
}/***
*@paramkey
*@paramvalue
*@return
*/
public Long lRightPushAll(String key, Collectionvalue) {returnredisTemplate.opsForList().rightPushAll(key, value);
}/*** 为已存在的列表添加值
*
*@paramkey
*@paramvalue
*@return
*/
publicLong lRightPushIfPresent(String key, String value) {returnredisTemplate.opsForList().rightPushIfPresent(key, value);
}/*** 在pivot元素的右边添加值
*
*@paramkey
*@parampivot
*@paramvalue
*@return
*/
publicLong lRightPush(String key, String pivot, String value) {returnredisTemplate.opsForList().rightPush(key, pivot, value);
}/*** 通过索引设置列表元素的值
*
*@paramkey
*@paramindex
* 位置
*@paramvalue*/
public void lSet(String key, longindex, String value) {
redisTemplate.opsForList().set(key, index, value);
}/*** 移出并获取列表的第一个元素
*
*@paramkey
*@return删除的元素*/
publicString lLeftPop(String key) {returnredisTemplate.opsForList().leftPop(key);
}/*** 移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
*
*@paramkey
*@paramtimeout
* 等待时间
*@paramunit
* 时间单位
*@return
*/
public String lBLeftPop(String key, longtimeout, TimeUnit unit) {returnredisTemplate.opsForList().leftPop(key, timeout, unit);
}/*** 移除并获取列表最后一个元素
*
*@paramkey
*@return删除的元素*/
publicString lRightPop(String key) {returnredisTemplate.opsForList().rightPop(key);
}/*** 移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
*
*@paramkey
*@paramtimeout
* 等待时间
*@paramunit
* 时间单位
*@return
*/
public String lBRightPop(String key, longtimeout, TimeUnit unit) {returnredisTemplate.opsForList().rightPop(key, timeout, unit);
}/*** 移除列表的最后一个元素,并将该元素添加到另一个列表并返回
*
*@paramsourceKey
*@paramdestinationKey
*@return
*/
publicString lRightPopAndLeftPush(String sourceKey, String destinationKey) {returnredisTemplate.opsForList().rightPopAndLeftPush(sourceKey,
destinationKey);
}/*** 从列表中弹出一个值,将弹出的元素插入到另外一个列表中并返回它; 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
*
*@paramsourceKey
*@paramdestinationKey
*@paramtimeout
*@paramunit
*@return
*/
publicString lBRightPopAndLeftPush(String sourceKey, String destinationKey,longtimeout, TimeUnit unit) {returnredisTemplate.opsForList().rightPopAndLeftPush(sourceKey,
destinationKey, timeout, unit);
}/*** 删除集合中值等于value得元素
*
*@paramkey
*@paramindex
* index=0, 删除所有值等于value的元素; index>0, 从头部开始删除第一个值等于value的元素;
* index<0, 从尾部开始删除第一个值等于value的元素;
*@paramvalue
*@return
*/
public Long lRemove(String key, longindex, String value) {returnredisTemplate.opsForList().remove(key, index, value);
}/*** 裁剪list
*
*@paramkey
*@paramstart
*@paramend*/
public void lTrim(String key, long start, longend) {
redisTemplate.opsForList().trim(key, start, end);
}/*** 获取列表长度
*
*@paramkey
*@return
*/
publicLong lLen(String key) {returnredisTemplate.opsForList().size(key);
}/**--------------------set相关操作--------------------------*/
/*** set添加元素
*
*@paramkey
*@paramvalues
*@return
*/
publicLong sAdd(String key, String... values) {returnredisTemplate.opsForSet().add(key, values);
}/*** set移除元素
*
*@paramkey
*@paramvalues
*@return
*/
publicLong sRemove(String key, Object... values) {returnredisTemplate.opsForSet().remove(key, values);
}/*** 移除并返回集合的一个随机元素
*
*@paramkey
*@return
*/
publicString sPop(String key) {returnredisTemplate.opsForSet().pop(key);
}/*** 将元素value从一个集合移到另一个集合
*
*@paramkey
*@paramvalue
*@paramdestKey
*@return
*/
publicBoolean sMove(String key, String value, String destKey) {returnredisTemplate.opsForSet().move(key, value, destKey);
}/*** 获取集合的大小
*
*@paramkey
*@return
*/
publicLong sSize(String key) {returnredisTemplate.opsForSet().size(key);
}/*** 判断集合是否包含value
*
*@paramkey
*@paramvalue
*@return
*/
publicBoolean sIsMember(String key, Object value) {returnredisTemplate.opsForSet().isMember(key, value);
}/*** 获取两个集合的交集
*
*@paramkey
*@paramotherKey
*@return
*/
public SetsIntersect(String key, String otherKey) {returnredisTemplate.opsForSet().intersect(key, otherKey);
}/*** 获取key集合与多个集合的交集
*
*@paramkey
*@paramotherKeys
*@return
*/
public Set sIntersect(String key, CollectionotherKeys) {returnredisTemplate.opsForSet().intersect(key, otherKeys);
}/*** key集合与otherKey集合的交集存储到destKey集合中
*
*@paramkey
*@paramotherKey
*@paramdestKey
*@return
*/
publicLong sIntersectAndStore(String key, String otherKey, String destKey) {returnredisTemplate.opsForSet().intersectAndStore(key, otherKey,
destKey);
}/*** key集合与多个集合的交集存储到destKey集合中
*
*@paramkey
*@paramotherKeys
*@paramdestKey
*@return
*/
public Long sIntersectAndStore(String key, CollectionotherKeys,
String destKey) {returnredisTemplate.opsForSet().intersectAndStore(key, otherKeys,
destKey);
}/*** 获取两个集合的并集
*
*@paramkey
*@paramotherKeys
*@return
*/
public SetsUnion(String key, String otherKeys) {returnredisTemplate.opsForSet().union(key, otherKeys);
}/*** 获取key集合与多个集合的并集
*
*@paramkey
*@paramotherKeys
*@return
*/
public Set sUnion(String key, CollectionotherKeys) {returnredisTemplate.opsForSet().union(key, otherKeys);
}/*** key集合与otherKey集合的并集存储到destKey中
*
*@paramkey
*@paramotherKey
*@paramdestKey
*@return
*/
publicLong sUnionAndStore(String key, String otherKey, String destKey) {returnredisTemplate.opsForSet().unionAndStore(key, otherKey, destKey);
}/*** key集合与多个集合的并集存储到destKey中
*
*@paramkey
*@paramotherKeys
*@paramdestKey
*@return
*/
public Long sUnionAndStore(String key, CollectionotherKeys,
String destKey) {returnredisTemplate.opsForSet().unionAndStore(key, otherKeys, destKey);
}/*** 获取两个集合的差集
*
*@paramkey
*@paramotherKey
*@return
*/
public SetsDifference(String key, String otherKey) {returnredisTemplate.opsForSet().difference(key, otherKey);
}/*** 获取key集合与多个集合的差集
*
*@paramkey
*@paramotherKeys
*@return
*/
public Set sDifference(String key, CollectionotherKeys) {returnredisTemplate.opsForSet().difference(key, otherKeys);
}/*** key集合与otherKey集合的差集存储到destKey中
*
*@paramkey
*@paramotherKey
*@paramdestKey
*@return
*/
publicLong sDifference(String key, String otherKey, String destKey) {returnredisTemplate.opsForSet().differenceAndStore(key, otherKey,
destKey);
}/*** key集合与多个集合的差集存储到destKey中
*
*@paramkey
*@paramotherKeys
*@paramdestKey
*@return
*/
public Long sDifference(String key, CollectionotherKeys,
String destKey) {returnredisTemplate.opsForSet().differenceAndStore(key, otherKeys,
destKey);
}/*** 获取集合所有元素
*
*@paramkey
*@return
*/
public SetsetMembers(String key) {returnredisTemplate.opsForSet().members(key);
}/*** 随机获取集合中的一个元素
*
*@paramkey
*@return
*/
publicString sRandomMember(String key) {returnredisTemplate.opsForSet().randomMember(key);
}/*** 随机获取集合中count个元素
*
*@paramkey
*@paramcount
*@return
*/
public List sRandomMembers(String key, longcount) {returnredisTemplate.opsForSet().randomMembers(key, count);
}/*** 随机获取集合中count个元素并且去除重复的
*
*@paramkey
*@paramcount
*@return
*/
public Set sDistinctRandomMembers(String key, longcount) {returnredisTemplate.opsForSet().distinctRandomMembers(key, count);
}/***
*@paramkey
*@paramoptions
*@return
*/
public CursorsScan(String key, ScanOptions options) {returnredisTemplate.opsForSet().scan(key, options);
}/**------------------zSet相关操作--------------------------------*/
/*** 添加元素,有序集合是按照元素的score值由小到大排列
*
*@paramkey
*@paramvalue
*@paramscore
*@return
*/
public Boolean zAdd(String key, String value, doublescore) {returnredisTemplate.opsForZSet().add(key, value, score);
}/***
*@paramkey
*@paramvalues
*@return
*/
public Long zAdd(String key, Set>values) {returnredisTemplate.opsForZSet().add(key, values);
}/***
*@paramkey
*@paramvalues
*@return
*/
publicLong zRemove(String key, Object... values) {returnredisTemplate.opsForZSet().remove(key, values);
}/*** 增加元素的score值,并返回增加后的值
*
*@paramkey
*@paramvalue
*@paramdelta
*@return
*/
public Double zIncrementScore(String key, String value, doubledelta) {returnredisTemplate.opsForZSet().incrementScore(key, value, delta);
}/*** 返回元素在集合的排名,有序集合是按照元素的score值由小到大排列
*
*@paramkey
*@paramvalue
*@return0表示第一位*/
publicLong zRank(String key, Object value) {returnredisTemplate.opsForZSet().rank(key, value);
}/*** 返回元素在集合的排名,按元素的score值由大到小排列
*
*@paramkey
*@paramvalue
*@return
*/
publicLong zReverseRank(String key, Object value) {returnredisTemplate.opsForZSet().reverseRank(key, value);
}/*** 获取集合的元素, 从小到大排序
*
*@paramkey
*@paramstart
* 开始位置
*@paramend
* 结束位置, -1查询所有
*@return
*/
public Set zRange(String key, long start, longend) {returnredisTemplate.opsForZSet().range(key, start, end);
}/*** 获取集合元素, 并且把score值也获取
*
*@paramkey
*@paramstart
*@paramend
*@return
*/
public Set> zRangeWithScores(String key, longstart,longend) {returnredisTemplate.opsForZSet().rangeWithScores(key, start, end);
}/*** 根据Score值查询集合元素
*
*@paramkey
*@parammin
* 最小值
*@parammax
* 最大值
*@return
*/
public Set zRangeByScore(String key, double min, doublemax) {returnredisTemplate.opsForZSet().rangeByScore(key, min, max);
}/*** 根据Score值查询集合元素, 从小到大排序
*
*@paramkey
*@parammin
* 最小值
*@parammax
* 最大值
*@return
*/
public Set>zRangeByScoreWithScores(String key,double min, doublemax) {returnredisTemplate.opsForZSet().rangeByScoreWithScores(key, min, max);
}/***
*@paramkey
*@parammin
*@parammax
*@paramstart
*@paramend
*@return
*/
public Set>zRangeByScoreWithScores(String key,double min, double max, long start, longend) {returnredisTemplate.opsForZSet().rangeByScoreWithScores(key, min, max,
start, end);
}/*** 获取集合的元素, 从大到小排序
*
*@paramkey
*@paramstart
*@paramend
*@return
*/
public Set zReverseRange(String key, long start, longend) {returnredisTemplate.opsForZSet().reverseRange(key, start, end);
}/*** 获取集合的元素, 从大到小排序, 并返回score值
*
*@paramkey
*@paramstart
*@paramend
*@return
*/
public Set>zReverseRangeWithScores(String key,long start, longend) {returnredisTemplate.opsForZSet().reverseRangeWithScores(key, start,
end);
}/*** 根据Score值查询集合元素, 从大到小排序
*
*@paramkey
*@parammin
*@parammax
*@return
*/
public Set zReverseRangeByScore(String key, doublemin,doublemax) {returnredisTemplate.opsForZSet().reverseRangeByScore(key, min, max);
}/*** 根据Score值查询集合元素, 从大到小排序
*
*@paramkey
*@parammin
*@parammax
*@return
*/
public Set>zReverseRangeByScoreWithScores(
String key,double min, doublemax) {returnredisTemplate.opsForZSet().reverseRangeByScoreWithScores(key,
min, max);
}/***
*@paramkey
*@parammin
*@parammax
*@paramstart
*@paramend
*@return
*/
public Set zReverseRangeByScore(String key, doublemin,double max, long start, longend) {returnredisTemplate.opsForZSet().reverseRangeByScore(key, min, max,
start, end);
}/*** 根据score值获取集合元素数量
*
*@paramkey
*@parammin
*@parammax
*@return
*/
public Long zCount(String key, double min, doublemax) {returnredisTemplate.opsForZSet().count(key, min, max);
}/*** 获取集合大小
*
*@paramkey
*@return
*/
publicLong zSize(String key) {returnredisTemplate.opsForZSet().size(key);
}/*** 获取集合大小
*
*@paramkey
*@return
*/
publicLong zZCard(String key) {returnredisTemplate.opsForZSet().zCard(key);
}/*** 获取集合中value元素的score值
*
*@paramkey
*@paramvalue
*@return
*/
publicDouble zScore(String key, Object value) {returnredisTemplate.opsForZSet().score(key, value);
}/*** 移除指定索引位置的成员
*
*@paramkey
*@paramstart
*@paramend
*@return
*/
public Long zRemoveRange(String key, long start, longend) {returnredisTemplate.opsForZSet().removeRange(key, start, end);
}/*** 根据指定的score值的范围来移除成员
*
*@paramkey
*@parammin
*@parammax
*@return
*/
public Long zRemoveRangeByScore(String key, double min, doublemax) {returnredisTemplate.opsForZSet().removeRangeByScore(key, min, max);
}/*** 获取key和otherKey的并集并存储在destKey中
*
*@paramkey
*@paramotherKey
*@paramdestKey
*@return
*/
publicLong zUnionAndStore(String key, String otherKey, String destKey) {returnredisTemplate.opsForZSet().unionAndStore(key, otherKey, destKey);
}/***
*@paramkey
*@paramotherKeys
*@paramdestKey
*@return
*/
public Long zUnionAndStore(String key, CollectionotherKeys,
String destKey) {returnredisTemplate.opsForZSet()
.unionAndStore(key, otherKeys, destKey);
}/*** 交集
*
*@paramkey
*@paramotherKey
*@paramdestKey
*@return
*/
publicLong zIntersectAndStore(String key, String otherKey,
String destKey) {returnredisTemplate.opsForZSet().intersectAndStore(key, otherKey,
destKey);
}/*** 交集
*
*@paramkey
*@paramotherKeys
*@paramdestKey
*@return
*/
public Long zIntersectAndStore(String key, CollectionotherKeys,
String destKey) {returnredisTemplate.opsForZSet().intersectAndStore(key, otherKeys,
destKey);
}/***
*@paramkey
*@paramoptions
*@return
*/
public Cursor>zScan(String key, ScanOptions options) {returnredisTemplate.opsForZSet().scan(key, options);
}
}