Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2011-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Set;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
import org.springframework.lang.Nullable;
/**
* Redis ZSet/sorted set specific operations.
*
* @author Costin Leau
* @author Christoph Strobl
* @author Mark Paluch
* @author Rosty Kerei
* @author Wongoo (望哥)
* @author Andrey Shlykov
*/
public interface ZSetOperations {
/**
* Typed ZSet tuple.
*/
interface TypedTuple extends Comparable> {
@Nullable
V getValue();
@Nullable
Double getScore();
}
/**
* Add {@code value} to a sorted set at {@code key}, or update its {@code score} if it already exists.
*
* @param key must not be {@literal null}.
* @param score the score.
* @param value the value.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZADD
*/
@Nullable
Boolean add(K key, V value, double score);
/**
* Add {@code tuples} to a sorted set at {@code key}, or update its {@code score} if it already exists.
*
* @param key must not be {@literal null}.
* @param tuples must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZADD
*/
@Nullable
Long add(K key, Set> tuples);
/**
* Remove {@code values} from sorted set. Return number of removed elements.
*
* @param key must not be {@literal null}.
* @param values must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREM
*/
@Nullable
Long remove(K key, Object... values);
/**
* Increment the score of element with {@code value} in sorted set by {@code increment}.
*
* @param key must not be {@literal null}.
* @param delta
* @param value the value.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZINCRBY
*/
@Nullable
Double incrementScore(K key, V value, double delta);
/**
* Determine the index of element with {@code value} in a sorted set.
*
* @param key must not be {@literal null}.
* @param o the value.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZRANK
*/
@Nullable
Long rank(K key, Object o);
/**
* Determine the index of element with {@code value} in a sorted set when scored high to low.
*
* @param key must not be {@literal null}.
* @param o the value.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREVRANK
*/
@Nullable
Long reverseRank(K key, Object o);
/**
* Get elements between {@code start} and {@code end} from sorted set.
*
* @param key must not be {@literal null}.
* @param start
* @param end
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZRANGE
*/
@Nullable
Set range(K key, long start, long end);
/**
* Get set of {@link Tuple}s between {@code start} and {@code end} from sorted set.
*
* @param key must not be {@literal null}.
* @param start
* @param end
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZRANGE
*/
@Nullable
Set> rangeWithScores(K key, long start, long end);
/**
* Get elements where score is between {@code min} and {@code max} from sorted set.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZRANGEBYSCORE
*/
@Nullable
Set rangeByScore(K key, double min, double max);
/**
* Get set of {@link Tuple}s where score is between {@code min} and {@code max} from sorted set.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZRANGEBYSCORE
*/
@Nullable
Set> rangeByScoreWithScores(K key, double min, double max);
/**
* Get elements in range from {@code start} to {@code end} where score is between {@code min} and {@code max} from
* sorted set.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @param offset
* @param count
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZRANGEBYSCORE
*/
@Nullable
Set rangeByScore(K key, double min, double max, long offset, long count);
/**
* Get set of {@link Tuple}s in range from {@code start} to {@code end} where score is between {@code min} and
* {@code max} from sorted set.
*
* @param key
* @param min
* @param max
* @param offset
* @param count
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZRANGEBYSCORE
*/
@Nullable
Set> rangeByScoreWithScores(K key, double min, double max, long offset, long count);
/**
* Get elements in range from {@code start} to {@code end} from sorted set ordered from high to low.
*
* @param key must not be {@literal null}.
* @param start
* @param end
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREVRANGE
*/
@Nullable
Set reverseRange(K key, long start, long end);
/**
* Get set of {@link Tuple}s in range from {@code start} to {@code end} from sorted set ordered from high to low.
*
* @param key must not be {@literal null}.
* @param start
* @param end
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREVRANGE
*/
@Nullable
Set> reverseRangeWithScores(K key, long start, long end);
/**
* Get elements where score is between {@code min} and {@code max} from sorted set ordered from high to low.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREVRANGEBYSCORE
*/
@Nullable
Set reverseRangeByScore(K key, double min, double max);
/**
* Get set of {@link Tuple} where score is between {@code min} and {@code max} from sorted set ordered from high to
* low.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREVRANGEBYSCORE
*/
@Nullable
Set> reverseRangeByScoreWithScores(K key, double min, double max);
/**
* Get elements in range from {@code start} to {@code end} where score is between {@code min} and {@code max} from
* sorted set ordered high -> low.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @param offset
* @param count
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREVRANGEBYSCORE
*/
@Nullable
Set reverseRangeByScore(K key, double min, double max, long offset, long count);
/**
* Get set of {@link Tuple} in range from {@code start} to {@code end} where score is between {@code min} and
* {@code max} from sorted set ordered high -> low.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @param offset
* @param count
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREVRANGEBYSCORE
*/
@Nullable
Set> reverseRangeByScoreWithScores(K key, double min, double max, long offset, long count);
/**
* Count number of elements within sorted set with scores between {@code min} and {@code max}.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZCOUNT
*/
@Nullable
Long count(K key, double min, double max);
/**
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
* lexicographical ordering.
*
* @param key must not be {@literal null}.
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see Redis Documentation: ZLEXCOUNT
*/
@Nullable
Long lexCount(K key, Range range);
/**
* Returns the number of elements of the sorted set stored with given {@code key}.
*
* @see #zCard(Object)
* @param key
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZCARD
*/
@Nullable
Long size(K key);
/**
* Get the size of sorted set with {@code key}.
*
* @param key must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 1.3
* @see Redis Documentation: ZCARD
*/
@Nullable
Long zCard(K key);
/**
* Get the score of element with {@code value} from sorted set with key {@code key}.
*
* @param key must not be {@literal null}.
* @param o the value.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZSCORE
*/
@Nullable
Double score(K key, Object o);
/**
* Remove elements in range between {@code start} and {@code end} from sorted set with {@code key}.
*
* @param key must not be {@literal null}.
* @param start
* @param end
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREMRANGEBYRANK
*/
@Nullable
Long removeRange(K key, long start, long end);
/**
* Remove elements with scores between {@code min} and {@code max} from sorted set with {@code key}.
*
* @param key must not be {@literal null}.
* @param min
* @param max
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZREMRANGEBYSCORE
*/
@Nullable
Long removeRangeByScore(K key, double min, double max);
/**
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKey must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZUNIONSTORE
*/
@Nullable
Long unionAndStore(K key, K otherKey, K destKey);
/**
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKeys must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZUNIONSTORE
*/
@Nullable
Long unionAndStore(K key, Collection otherKeys, K destKey);
/**
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKeys must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @param aggregate must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.1
* @see Redis Documentation: ZUNIONSTORE
*/
@Nullable
default Long unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) {
return unionAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size()));
}
/**
* Union sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKeys must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @param aggregate must not be {@literal null}.
* @param weights must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.1
* @see Redis Documentation: ZUNIONSTORE
*/
@Nullable
Long unionAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate, Weights weights);
/**
* Intersect sorted sets at {@code key} and {@code otherKey} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKey must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZINTERSTORE
*/
@Nullable
Long intersectAndStore(K key, K otherKey, K destKey);
/**
* Intersect sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKeys must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZINTERSTORE
*/
@Nullable
Long intersectAndStore(K key, Collection otherKeys, K destKey);
/**
* Intersect sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKeys must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @param aggregate must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.1
* @see Redis Documentation: ZINTERSTORE
*/
@Nullable
default Long intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate) {
return intersectAndStore(key, otherKeys, destKey, aggregate, Weights.fromSetCount(1 + otherKeys.size()));
}
/**
* Intersect sorted sets at {@code key} and {@code otherKeys} and store result in destination {@code destKey}.
*
* @param key must not be {@literal null}.
* @param otherKeys must not be {@literal null}.
* @param destKey must not be {@literal null}.
* @param aggregate must not be {@literal null}.
* @param weights must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.1
* @see Redis Documentation: ZINTERSTORE
*/
@Nullable
Long intersectAndStore(K key, Collection otherKeys, K destKey, Aggregate aggregate, Weights weights);
/**
* Iterate over elements in zset at {@code key}.
* Important: Call {@link Cursor#close()} when done to avoid resource leak.
*
* @param key
* @param options
* @return {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: ZSCAN
* @since 1.4
*/
Cursor> scan(K key, ScanOptions options);
/**
* Get all elements with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
* {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}.
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 1.7
* @see Redis Documentation: ZRANGEBYLEX
*/
@Nullable
default Set rangeByLex(K key, Range range) {
return rangeByLex(key, range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with lexicographical ordering from {@literal ZSET} at {@code key} with a value between
* {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 1.7
* @see Redis Documentation: ZRANGEBYLEX
*/
@Nullable
Set rangeByLex(K key, Range range, Limit limit);
/**
* Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between
* {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}.
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see Redis Documentation: ZREVRANGEBYLEX
*/
@Nullable
default Set reverseRangeByLex(K key, Range range) {
return reverseRangeByLex(key, range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value
* between {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see Redis Documentation: ZREVRANGEBYLEX
*/
@Nullable
Set reverseRangeByLex(K key, Range range, Limit limit);
/**
* @return never {@literal null}.
*/
RedisOperations getOperations();
}