ZRANGE
ZRANGE key start stop [BYSCORE | BYLEX] [REV] [LIMIT offset count] [WITHSCORES]
zrange(
name: KeyT,
start: EncodableT,
end: EncodableT,
desc: bool = False,
withscores: bool = False,
score_cast_func: Union[type, Callable] = float,
byscore: bool = False,
bylex: bool = False,
offset: Optional[int] = None,
num: Optional[int] = None
) → ResponseT
ZRANGE(
key: RedisArgument,
min: RedisArgument | number,
max: RedisArgument | number,
options?: ZRangeOptions
) → Any
ZRANGE_WITHSCORES(
...args: Parameters<typeof ZRANGE.parseCommand>
) → Any
zrangeWithScores(
key: byte[],
start: long,
stop: long
) → List<Tuple>
zrangeWithScores(
key: byte[],
zRangeParams: ZRangeParams
) → List<Tuple>
zrange(
key: String,
start: long,
stop: long
) → List<String>
zrangeWithScores(
key: String,
start: long,
stop: long
) → List<Tuple>
zrange(
key: String,
zRangeParams: ZRangeParams
) → List<String>
zrange(
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → List<V> // Long count of elements in the specified range.
zrange(
channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → Long // Long count of elements in the specified range.
zrangeWithScores(
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → List<ScoredValue<V>> // Long count of elements in the specified range.
zrangeWithScores(
channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → Long // Long count of elements in the specified range.
zrange(
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → RedisFuture<List<V>> // Long count of elements in the specified range.
zrange(
channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → RedisFuture<Long> // Long count of elements in the specified range.
zrangeWithScores(
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → RedisFuture<List<ScoredValue<V>>> // Long count of elements in the specified range.
zrangeWithScores(
channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → RedisFuture<Long> // Long count of elements in the specified range.
zrange(
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → Flux<V> // Long count of elements in the specified range. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #zrange.
zrange(
channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → Mono<Long> // Long count of elements in the specified range. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #zrange.
zrangeWithScores(
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → Flux<ScoredValue<V>> // Long count of elements in the specified range. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #zrangeWithScores.
zrangeWithScores(
channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
key: K, // the key.
start: long, // the start.
stop: long // the stop.
) → Mono<Long> // Long count of elements in the specified range. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #zrangeWithScores.
ZRange(
ctx: context.Context,
key: string,
start: Any,
stop: int64
) → *StringSliceCmd
ZRangeWithScores(
ctx: context.Context,
key: string,
start: Any,
stop: int64
) → *ZSliceCmd
SortedSetRangeByRank(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // List of elements in the specified range.
SortedSetRangeByRankWithScores(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → SortedSetEntry[] // List of elements in the specified range.
SortedSetRangeByRank(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // List of elements in the specified range.
SortedSetRangeByRankWithScores(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → SortedSetEntry[] // List of elements in the specified range.
SortedSetRangeByScore(
key: RedisKey, // The key of the sorted set.
start: double, // The minimum score to filter by.
stop: double, // The maximum score to filter by.
exclude: Exclude, // Which of start and stop to exclude (defaults to both inclusive).
order: Order, // The order to sort by (defaults to ascending).
skip: long, // How many items to skip.
take: long, // How many items to take.
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // List of elements in the specified score range.
SortedSetRangeByRank(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // List of elements in the specified range.
SortedSetRangeByRankWithScores(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → SortedSetEntry[] // List of elements in the specified range.
SortedSetRangeByRank(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // List of elements in the specified range.
SortedSetRangeByRankWithScores(
key: RedisKey, // The key of the sorted set.
start: long, // The start index to get.
stop: long, // The stop index to get.
order: Order, // The order to sort by (defaults to ascending).
flags: CommandFlags // The flags to use for this operation.
) → SortedSetEntry[] // List of elements in the specified range.
SortedSetRangeByScore(
key: RedisKey, // The key of the sorted set.
start: double, // The minimum score to filter by.
stop: double, // The maximum score to filter by.
exclude: Exclude, // Which of start and stop to exclude (defaults to both inclusive).
order: Order, // The order to sort by (defaults to ascending).
skip: long, // How many items to skip.
take: long, // How many items to take.
flags: CommandFlags // The flags to use for this operation.
) → RedisValue[] // List of elements in the specified score range.
zrange(
$key: string,
$start: int|string,
$stop: int|string,
?array $options = null: Any
) → array
zrange(
key: K,
start: isize,
stop: isize
) → (Vec<String>)
zrange_withscores(
key: K,
start: isize,
stop: isize
) → (Vec<(String, f64)>)
zrange(
key: K,
start: isize,
stop: isize
) → (Vec<String>)
zrange_withscores(
key: K,
start: isize,
stop: isize
) → (Vec<(String, f64)>)
- Available since:
- Redis Open Source 1.2.0
- Time complexity:
- O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
- ACL categories:
-
@read,@sortedset,@slow, - Compatibility:
- Redis Software and Redis Cloud compatibility
Returns the specified range of elements in the sorted set stored at <key>.
ZRANGE can perform different types of range queries: by index (rank), by the score, or by lexicographical order.
Starting with Redis 6.2.0, this command can replace the following commands: ZREVRANGE, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZRANGEBYLEX and ZREVRANGEBYLEX.
Required arguments
key
The name of the key that holds the sorted set.
start
The start of the range. By default a zero-based index (negatives count from the end); a score bound with BYSCORE; or a lexicographical bound with BYLEX.
stop
The end of the range, inclusive. Interpreted the same way as start.
Optional arguments
BYSCORE | BYLEX
Interpret the range as a score range (BYSCORE) or a lexicographical range (BYLEX) instead of an index range.
REV
Reverse the ordering so results are returned from high to low.
LIMIT offset count
Skip offset matching members and return up to count of them. Requires BYSCORE or BYLEX. A negative count returns all remaining members.
WITHSCORES
Also return the score of each member.
Examples
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
res = r.zadd("myzset", {"one": 1, "two":2, "three":3})
print(res)
# >>> 3
res = r.zrange("myzset", 0, -1)
print(res)
# >>> ['one', 'two', 'three']
res = r.zrange("myzset", 2, 3)
print(res)
# >>> ['three']
res = r.zrange("myzset", -2, -1)
print(res)
# >>> ['two', 'three']
import redis
r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True)
res = r.zadd("myzset", {"one": 1})
print(res)
# >>> 1
res = r.zadd("myzset", {"uno": 1})
print(res)
# >>> 1
res = r.zadd("myzset", {"two": 2, "three": 3})
print(res)
# >>> 2
res = r.zrange("myzset", 0, -1, withscores=True)
# >>> [('one', 1.0), ('uno', 1.0), ('two', 2.0), ('three', 3.0)]
res = r.zadd("myzset", {"one": 1, "two":2, "three":3})
print(res)
# >>> 3
res = r.zrange("myzset", 0, -1)
print(res)
# >>> ['one', 'two', 'three']
res = r.zrange("myzset", 2, 3)
print(res)
# >>> ['three']
res = r.zrange("myzset", -2, -1)
print(res)
# >>> ['two', 'three']
res = r.zadd("myzset", {"one": 1, "two":2, "three":3})
res = r.zrange("myzset", 0, 1, withscores=True)
print(res)
# >>> [('one', 1.0), ('two', 2.0)]
res = r.zadd("myzset", {"one": 1, "two":2, "three":3})
res = r.zrange("myzset", 2, 3, byscore=True, offset=1, num=1)
print(res)
# >>> ['three']
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- name: KeyT,
- mapping: Mapping[AnyKeyT, EncodableT],
- nx: bool = False,
- xx: bool = False,
- ch: bool = False,
- incr: bool = False,
- gt: bool = False,
- lt: bool = False
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- name: KeyT,
- start: EncodableT,
- end: EncodableT,
- desc: bool = False,
- withscores: bool = False,
- score_cast_func: Union[type, Callable] = float,
- byscore: bool = False,
- bylex: bool = False,
- offset: Optional[int] = None,
- num: Optional[int] = None
-
zrange(
const val5 = await client.zAdd("myzset", [
{ value: 'one', score: 1 },
{ value: 'two', score: 2 },
{ value: 'three', score: 3 }
]);
console.log(val5);
// returns 3
const val6 = await client.zRange('myzset', 0, -1);
console.log(val6);
// returns ['one', 'two', 'three']
const val7 = await client.zRange('myzset', 2, 3);
console.log(val7);
// returns ['three']
const val8 = await client.zRange('myzset', -2, -1);
console.log(val8);
// returns ['two', 'three']
import { createClient } from 'redis';
const client = createClient();
client.on('error', err => console.log('Redis Client Error', err));
await client.connect().catch(console.error);
const val1 = await client.zAdd("myzset", [{ value: 'one', score: 1 }]);
console.log(val1);
// returns 1
const val2 = await client.zAdd("myzset", [{ value: 'uno', score: 1 }]);
console.log(val2);
// returns 1
const val3 = await client.zAdd("myzset", [{ value: 'two', score: 2 }, { value: 'three', score: 3 }]);
console.log(val3);
// returns 2
const val4 = await client.zRangeWithScores("myzset", 0, -1);
console.log(val4);
// returns [{value: 'one', score: 1}, {value: 'uno', score: 1}, {value: 'two', score: 2}, {value: 'three', score: 3} ]
const val5 = await client.zAdd("myzset", [
{ value: 'one', score: 1 },
{ value: 'two', score: 2 },
{ value: 'three', score: 3 }
]);
console.log(val5);
// returns 3
const val6 = await client.zRange('myzset', 0, -1);
console.log(val6);
// returns ['one', 'two', 'three']
const val7 = await client.zRange('myzset', 2, 3);
console.log(val7);
// returns ['three']
const val8 = await client.zRange('myzset', -2, -1);
console.log(val8);
// returns ['two', 'three']
const val9 = await client.zAdd("myzset", [
{ value: 'one', score: 1 },
{ value: 'two', score: 2 },
{ value: 'three', score: 3 }
]);
console.log(val9);
// returns 3
const val10 = await client.zRangeWithScores('myzset', 0, 1);
console.log(val10);
// returns [{value: 'one', score: 1}, {value: 'two', score: 2}]
const val11 = await client.zAdd("myzset", [
{ value: 'one', score: 1 },
{ value: 'two', score: 2 },
{ value: 'three', score: 3 }
]);
console.log(val11);
// returns 3
const val12 = await client.zRange('myzset', 2, 3, { BY: 'SCORE', LIMIT: { offset: 1, count: 1 } });
console.log(val12);
// >>> ['three']
await client.close();
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
ZADD(
- key: RedisArgument,
- members: SortedSetMember | Array<SortedSetMember>,
- options?: ZAddOptions
-
ZADD(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
ZRANGE(
- key: RedisArgument,
- min: RedisArgument | number,
- max: RedisArgument | number,
- options?: ZRangeOptions
-
ZRANGE_WITHSCORES(
- ...args: Parameters<typeof ZRANGE.parseCommand>
-
ZRANGE(
const res5 = await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');
console.log(res5); // >>> 3
const res6 = await redis.zrange('myzset', 0, -1);
console.log(res6); // >>> ['one', 'two', 'three']
const res7 = await redis.zrange('myzset', 2, 3);
console.log(res7); // >>> ['three']
const res8 = await redis.zrange('myzset', -2, -1);
console.log(res8); // >>> ['two', 'three']
import assert from 'node:assert';
import { Redis } from 'ioredis';
const redis = new Redis();
const res1 = await redis.zadd('myzset', 1, 'one');
console.log(res1); // >>> 1
const res2 = await redis.zadd('myzset', 1, 'uno');
console.log(res2); // >>> 1
const res3 = await redis.zadd('myzset', 2, 'two', 3, 'three');
console.log(res3); // >>> 2
const res4 = await redis.zrange('myzset', 0, -1, 'WITHSCORES');
console.log(res4); // >>> ['one', '1', 'uno', '1', 'two', '2', 'three', '3']
const res5 = await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');
console.log(res5); // >>> 3
const res6 = await redis.zrange('myzset', 0, -1);
console.log(res6); // >>> ['one', 'two', 'three']
const res7 = await redis.zrange('myzset', 2, 3);
console.log(res7); // >>> ['three']
const res8 = await redis.zrange('myzset', -2, -1);
console.log(res8); // >>> ['two', 'three']
await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');
const res9 = await redis.zrange('myzset', 0, 1, 'WITHSCORES');
console.log(res9); // >>> ['one', '1', 'two', '2']
await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');
const res10 = await redis.zrange('myzset', '(1', '+inf', 'BYSCORE', 'LIMIT', 1, 1);
console.log(res10); // >>> ['three']
redis.disconnect();
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [key
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [, key
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- withscores: "WITHSCORES",
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- offsetCountToken: "LIMIT",
- offset: number | string,
- count: number | string,
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- offsetCountToken: "LIMIT",
- offset: number | string,
- count: number | string,
- withscores: "WITHSCORES",
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- rev: "REV",
- callback?: Callback<string[]>
-
zrange(
Map<String, Double> zRangeExampleParams1 = new HashMap<>();
zRangeExampleParams1.put("one", 1.0);
zRangeExampleParams1.put("two", 2.0);
zRangeExampleParams1.put("three", 3.0);
long zRangeResult1 = jedis.zadd("myzset", zRangeExampleParams1);
System.out.println(zRangeResult1); // >>> 3
List<String> zRangeResult2 = jedis.zrange("myzset", new ZRangeParams(0, -1));
System.out.println(String.join(", ", zRangeResult2)); // >>> one, two, three
List<String> zRangeResult3 = jedis.zrange("myzset", new ZRangeParams(2, 3));
System.out.println(String.join(", ", zRangeResult3)); // >> three
List<String> zRangeResult4 = jedis.zrange("myzset", new ZRangeParams(-2, -1));
System.out.println(String.join(", ", zRangeResult4)); // >> two, three
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import redis.clients.jedis.RedisClient;
import redis.clients.jedis.params.ZRangeParams;
import redis.clients.jedis.resps.Tuple;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class CmdsSortedSetExample {
public void run() {
RedisClient jedis = RedisClient.create("redis://localhost:6379");
// Tests for 'bzmpop' step.
// Tests for 'bzpopmax' step.
// Tests for 'bzpopmin' step.
Map<String, Double> zAddExampleParams = new HashMap<>();
zAddExampleParams.put("one", 1.0);
long zAddResult1 = jedis.zadd("myzset", zAddExampleParams);
System.out.println(zAddResult1); // >>> 1
zAddExampleParams.clear();
zAddExampleParams.put("uno", 1.0);
long zAddResult2 = jedis.zadd("myzset", zAddExampleParams);
System.out.println(zAddResult2); // >>> 1
zAddExampleParams.clear();
zAddExampleParams.put("two", 2.0);
zAddExampleParams.put("three", 3.0);
long zAddResult3 = jedis.zadd("myzset", zAddExampleParams);
System.out.println(zAddResult3); // >>> 2
List<Tuple> zAddResult4 = jedis.zrangeWithScores("myzset", new ZRangeParams(0, -1));
for (Tuple item: zAddResult4) {
System.out.println("Element: " + item.getElement() + ", Score: " + item.getScore());
}
// >>> Element: one, Score: 1.0
// >>> Element: uno, Score: 1.0
// >>> Element: two, Score: 2.0
// >>> Element: three, Score: 3.0
// Tests for 'zadd' step.
// Tests for 'zcard' step.
// Tests for 'zcount' step.
// Tests for 'zdiff' step.
// Tests for 'zdiffstore' step.
// Tests for 'zincrby' step.
// Tests for 'zinter' step.
// Tests for 'zintercard' step.
// Tests for 'zinterstore' step.
// Tests for 'zlexcount' step.
// Tests for 'zmpop' step.
// Tests for 'zmscore' step.
// Tests for 'zpopmax' step.
// Tests for 'zpopmin' step.
// Tests for 'zrandmember' step.
Map<String, Double> zRangeExampleParams1 = new HashMap<>();
zRangeExampleParams1.put("one", 1.0);
zRangeExampleParams1.put("two", 2.0);
zRangeExampleParams1.put("three", 3.0);
long zRangeResult1 = jedis.zadd("myzset", zRangeExampleParams1);
System.out.println(zRangeResult1); // >>> 3
List<String> zRangeResult2 = jedis.zrange("myzset", new ZRangeParams(0, -1));
System.out.println(String.join(", ", zRangeResult2)); // >>> one, two, three
List<String> zRangeResult3 = jedis.zrange("myzset", new ZRangeParams(2, 3));
System.out.println(String.join(", ", zRangeResult3)); // >> three
List<String> zRangeResult4 = jedis.zrange("myzset", new ZRangeParams(-2, -1));
System.out.println(String.join(", ", zRangeResult4)); // >> two, three
// Tests for 'zrange1' step.
Map<String, Double> zRangeExampleParams2 = new HashMap<>();
zRangeExampleParams2.put("one", 1.0);
zRangeExampleParams2.put("two", 2.0);
zRangeExampleParams2.put("three", 3.0);
long zRangeResult5 = jedis.zadd("myzset", zRangeExampleParams2);
System.out.println(zRangeResult5); // >>> 3
List<Tuple> zRangeResult6 = jedis.zrangeWithScores("myzset", new ZRangeParams(0, 1));
for (Tuple item: zRangeResult6) {
System.out.println("Element: " + item.getElement() + ", Score: " + item.getScore());
}
// >>> Element: one, Score: 1.0
// >>> Element: two, Score: 2.0
// Tests for 'zrange2' step.
Map<String, Double> zRangeExampleParams3 = new HashMap<>();
zRangeExampleParams3.put("one", 1.0);
zRangeExampleParams3.put("two", 2.0);
zRangeExampleParams3.put("three", 3.0);
long zRangeResult7 = jedis.zadd("myzset", zRangeExampleParams3);
System.out.println(zRangeResult7); // >>> 3
List<String> zRangeResult8 = jedis.zrangeByScore("myzset", "(1", "+inf", 1, 1);
System.out.println(String.join(", ", zRangeResult8)); // >>> three
// Tests for 'zrange3' step.
// Tests for 'zrangebylex' step.
// Tests for 'zrangebyscore' step.
// Tests for 'zrangestore' step.
// Tests for 'zrank' step.
// Tests for 'zrem' step.
// Tests for 'zremrangebylex' step.
// Tests for 'zremrangebyrank' step.
// Tests for 'zremrangebyscore' step.
// Tests for 'zrevrange' step.
// Tests for 'zrevrangebylex' step.
// Tests for 'zrevrangebyscore' step.
// Tests for 'zrevrank' step.
// Tests for 'zscan' step.
// Tests for 'zscore' step.
// Tests for 'zunion' step.
// Tests for 'zunionstore' step.
jedis.close();
}
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: byte[],
- score: double,
- member: byte[]
-
zadd(
- key: byte[],
- score: double,
- params: byte[] member final ZAddParams
-
zadd(
- key: byte[],
- scoreMembers: Map<byte[], Double>
-
zadd(
- key: byte[],
- scoreMembers: Map<byte[], Double>,
- params: ZAddParams
-
zadd(
- key: String,
- score: double,
- member: String
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrangeWithScores(
- key: byte[],
- start: long,
- stop: long
-
zrangeWithScores(
- key: byte[],
- zRangeParams: ZRangeParams
-
zrange(
- key: String,
- start: long,
- stop: long
-
zrangeWithScores(
- key: String,
- start: long,
- stop: long
-
zrange(
- key: String,
- zRangeParams: ZRangeParams
-
zrangeWithScores(
CompletableFuture<Void> zRange1Example = asyncCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.thenCompose(res5 -> {
System.out.println(res5); // >>> 3
return asyncCommands.zrange("myzset", 0, -1);
}).thenCompose(res6 -> {
System.out.println(res6); // >>> [one, two, three]
return asyncCommands.zrange("myzset", 2, 3);
}).thenCompose(res7 -> {
System.out.println(res7); // >>> [three]
return asyncCommands.zrange("myzset", -2, -1);
}).thenAccept(res8 -> {
System.out.println(res8); // >>> [two, three]
}).toCompletableFuture();
package io.redis.examples.async;
import io.lettuce.core.*;
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.core.api.StatefulRedisConnection;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class CmdsSortedSetExample {
public void run() {
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
RedisAsyncCommands<String, String> asyncCommands = connection.async();
CompletableFuture<Void> zAddExample = asyncCommands.zadd("myzset", ScoredValue.just(1d, "one"))
.thenCompose(res1 -> {
System.out.println(res1); // >>> 1
return asyncCommands.zadd("myzset", ScoredValue.just(1d, "uno"));
}).thenCompose(res2 -> {
System.out.println(res2); // >>> 1
return asyncCommands.zadd("myzset",
ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"));
}).thenCompose(res3 -> {
System.out.println(res3); // >>> 2
return asyncCommands.zrangeWithScores("myzset", 0, -1);
}).thenAccept(res4 -> {
System.out.println(res4);
// >>> [ScoredValue[1.000000, one], ScoredValue[1.000000, uno],
// >>> ScoredValue[2.000000, two], ScoredValue[3.000000, three]]
}).toCompletableFuture();
zAddExample.join();
CompletableFuture<Void> zRange1Example = asyncCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.thenCompose(res5 -> {
System.out.println(res5); // >>> 3
return asyncCommands.zrange("myzset", 0, -1);
}).thenCompose(res6 -> {
System.out.println(res6); // >>> [one, two, three]
return asyncCommands.zrange("myzset", 2, 3);
}).thenCompose(res7 -> {
System.out.println(res7); // >>> [three]
return asyncCommands.zrange("myzset", -2, -1);
}).thenAccept(res8 -> {
System.out.println(res8); // >>> [two, three]
}).toCompletableFuture();
zRange1Example.join();
CompletableFuture<Void> zRange2Example = asyncCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.thenCompose(res9 -> {
return asyncCommands.zrangeWithScores("myzset", 0, 1);
}).thenAccept(res10 -> {
System.out.println(res10);
// >>> [ScoredValue[1.000000, one], ScoredValue[2.000000, two]]
}).toCompletableFuture();
zRange2Example.join();
CompletableFuture<Void> zRange3Example = asyncCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.thenCompose(res11 -> {
return asyncCommands.zrangebyscore("myzset",
Range.from(Range.Boundary.excluding(1d), Range.Boundary.unbounded()),
Limit.create(1, 1));
}).thenAccept(res12 -> {
System.out.println(res12); // >>> [three]
}).toCompletableFuture();
zRange3Example.join();
} finally {
redisClient.shutdown();
}
}
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K, // the ke.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- scoresAndValues: Object...
-
zadd(
- key: K, // the ke.
- scoredValues: ScoredValue<V>... // the scored values.
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- scoresAndValues: Object...
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
- channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
Mono<Void> zRange1Example = reactiveCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.doOnNext(res5 -> {
System.out.println(res5); // >>> 3
})
.then(reactiveCommands.zrange("myzset", 0, -1).collectList())
.doOnNext(res6 -> {
System.out.println(res6); // >>> [one, two, three]
})
.then(reactiveCommands.zrange("myzset", 2, 3).collectList())
.doOnNext(res7 -> {
System.out.println(res7); // >>> [three]
})
.then(reactiveCommands.zrange("myzset", -2, -1).collectList())
.doOnNext(res8 -> {
System.out.println(res8); // >>> [two, three]
})
.then();
package io.redis.examples.reactive;
import io.lettuce.core.*;
import io.lettuce.core.api.reactive.RedisReactiveCommands;
import io.lettuce.core.api.StatefulRedisConnection;
import java.util.*;
import java.util.stream.Collectors;
import reactor.core.publisher.Mono;
public class CmdsSortedSetExample {
public void run() {
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
RedisReactiveCommands<String, String> reactiveCommands = connection.reactive();
Mono<Void> zAddExample = reactiveCommands.zadd("myzset", ScoredValue.just(1d, "one"))
.doOnNext(res1 -> {
System.out.println(res1); // >>> 1
})
.then(reactiveCommands.zadd("myzset", ScoredValue.just(1d, "uno")))
.doOnNext(res2 -> {
System.out.println(res2); // >>> 1
})
.then(reactiveCommands.zadd("myzset",
ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three")))
.doOnNext(res3 -> {
System.out.println(res3); // >>> 2
})
.then(reactiveCommands.zrangeWithScores("myzset", 0, -1).collectList())
.doOnNext(res4 -> {
System.out.println(res4);
// >>> [ScoredValue[1.000000, one], ScoredValue[1.000000, uno],
// >>> ScoredValue[2.000000, two], ScoredValue[3.000000, three]]
})
.then();
zAddExample.block();
Mono<Void> zRange1Example = reactiveCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.doOnNext(res5 -> {
System.out.println(res5); // >>> 3
})
.then(reactiveCommands.zrange("myzset", 0, -1).collectList())
.doOnNext(res6 -> {
System.out.println(res6); // >>> [one, two, three]
})
.then(reactiveCommands.zrange("myzset", 2, 3).collectList())
.doOnNext(res7 -> {
System.out.println(res7); // >>> [three]
})
.then(reactiveCommands.zrange("myzset", -2, -1).collectList())
.doOnNext(res8 -> {
System.out.println(res8); // >>> [two, three]
})
.then();
zRange1Example.block();
Mono<Void> zRange2Example = reactiveCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.then(reactiveCommands.zrangeWithScores("myzset", 0, 1).collectList())
.doOnNext(res9 -> {
System.out.println(res9);
// >>> [ScoredValue[1.000000, one], ScoredValue[2.000000, two]]
})
.then();
zRange2Example.block();
Mono<Void> zRange3Example = reactiveCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.then(reactiveCommands.zrangebyscore("myzset",
Range.from(Range.Boundary.excluding(1d), Range.Boundary.unbounded()),
Limit.create(1, 1)).collectList())
.doOnNext(res10 -> {
System.out.println(res10); // >>> [three]
})
.then();
zRange3Example.block();
} finally {
redisClient.shutdown();
}
}
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K, // the ke.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- scoresAndValues: Object...
-
zadd(
- key: K, // the ke.
- scoredValues: ScoredValue<V>... // the scored values.
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- scoresAndValues: Object...
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
- channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
zrangeResult1, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "one", Score: 1},
redis.Z{Member: "two", Score: 2},
redis.Z{Member: "three", Score: 3},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult1) // >>> 3
zrangeResult2, err := rdb.ZRange(ctx, "myzset", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult2) // >>> [one two three]
zrangeResult3, err := rdb.ZRange(ctx, "myzset", 2, 3).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult3) // >>> [three]
zrangeResult4, err := rdb.ZRange(ctx, "myzset", -2, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult4) // >>> [two three]
package example_commands_test
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
func ExampleClient_zadd_cmd() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
zAddResult1, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "one", Score: 1},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zAddResult1) // >>> 1
zAddResult2, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "uno", Score: 1},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zAddResult2)
zAddResult3, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "two", Score: 2},
redis.Z{Member: "three", Score: 3},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zAddResult3) // >>> 2
zAddResult4, err := rdb.ZRangeWithScores(ctx, "myzset", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(zAddResult4) // >>> [{1 one} {1 uno} {2 two} {3 three}]
}
func ExampleClient_zrange1() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
zrangeResult1, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "one", Score: 1},
redis.Z{Member: "two", Score: 2},
redis.Z{Member: "three", Score: 3},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult1) // >>> 3
zrangeResult2, err := rdb.ZRange(ctx, "myzset", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult2) // >>> [one two three]
zrangeResult3, err := rdb.ZRange(ctx, "myzset", 2, 3).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult3) // >>> [three]
zrangeResult4, err := rdb.ZRange(ctx, "myzset", -2, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(zrangeResult4) // >>> [two three]
}
func ExampleClient_zrange2() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
zRangeResult5, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "one", Score: 1},
redis.Z{Member: "two", Score: 2},
redis.Z{Member: "three", Score: 3},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult5) // >>> 3
zRangeResult6, err := rdb.ZRangeWithScores(ctx, "myzset", 0, 1).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult6) // >>> [{1 one} {2 two}]
}
func ExampleClient_zrange3() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
zRangeResult7, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "one", Score: 1},
redis.Z{Member: "two", Score: 2},
redis.Z{Member: "three", Score: 3},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult7) // >>> 3
zRangeResult8, err := rdb.ZRangeArgs(ctx,
redis.ZRangeArgs{
Key: "myzset",
ByScore: true,
Start: "(1",
Stop: "+inf",
Offset: 1,
Count: 1,
},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult8) // >>> [three]
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
ZAdd(
- ctx: context.Context,
- key: string,
- members: ...Z
-
ZAdd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
ZRange(
- ctx: context.Context,
- key: string,
- start: Any,
- stop: int64
-
ZRangeWithScores(
- ctx: context.Context,
- key: string,
- start: Any,
- stop: int64
-
ZRange(
long zRangeResult1 = db.SortedSetAdd(
"myzset",
[
new("one", 1),
new("two", 2),
new("three", 3)
]
);
Console.WriteLine(zRangeResult1); // >>> 3
RedisValue[] zRangeResult2 = db.SortedSetRangeByRank("myzset", 0, -1);
Console.WriteLine(string.Join(", ", zRangeResult2));
// >>> one, two, three
RedisValue[] zRangeResult3 = db.SortedSetRangeByRank("myzset", 2, 3);
Console.WriteLine(string.Join(", ", zRangeResult3));
// >>> three
RedisValue[] zRangeResult4 = db.SortedSetRangeByRank("myzset", -2, -1);
Console.WriteLine(string.Join(", ", zRangeResult4));
// >>> two, three
using NRedisStack.Tests;
using StackExchange.Redis;
public class CmdsSortedSet
{
public void Run()
{
var muxer = ConnectionMultiplexer.Connect("localhost:6379");
var db = muxer.GetDatabase();
// Tests for 'bzmpop' step.
// Tests for 'bzpopmax' step.
// Tests for 'bzpopmin' step.
bool zAddResult1 = db.SortedSetAdd("myzset", "one", 1);
Console.WriteLine(zAddResult1); // >>> True
bool zAddResult2 = db.SortedSetAdd("myzset", "uno", 1);
Console.WriteLine(zAddResult2); // >>> True
long zAddResult3 = db.SortedSetAdd(
"myzset",
[
new("two", 2),
new("three", 3)
]
);
Console.WriteLine(zAddResult3); // >>> 2
SortedSetEntry[] zAddResult4 = db.SortedSetRangeByRankWithScores("myzset", 0, -1);
Console.WriteLine($"{string.Join(", ", zAddResult4.Select(b => $"{b.Element}: {b.Score}"))}");
// >>> one: 1, uno: 1, two: 2, three: 3
// Tests for 'zadd' step.
// Tests for 'zcard' step.
// Tests for 'zcount' step.
// Tests for 'zdiff' step.
// Tests for 'zdiffstore' step.
// Tests for 'zincrby' step.
// Tests for 'zinter' step.
// Tests for 'zintercard' step.
// Tests for 'zinterstore' step.
// Tests for 'zlexcount' step.
// Tests for 'zmpop' step.
// Tests for 'zmscore' step.
// Tests for 'zpopmax' step.
// Tests for 'zpopmin' step.
// Tests for 'zrandmember' step.
long zRangeResult1 = db.SortedSetAdd(
"myzset",
[
new("one", 1),
new("two", 2),
new("three", 3)
]
);
Console.WriteLine(zRangeResult1); // >>> 3
RedisValue[] zRangeResult2 = db.SortedSetRangeByRank("myzset", 0, -1);
Console.WriteLine(string.Join(", ", zRangeResult2));
// >>> one, two, three
RedisValue[] zRangeResult3 = db.SortedSetRangeByRank("myzset", 2, 3);
Console.WriteLine(string.Join(", ", zRangeResult3));
// >>> three
RedisValue[] zRangeResult4 = db.SortedSetRangeByRank("myzset", -2, -1);
Console.WriteLine(string.Join(", ", zRangeResult4));
// >>> two, three
// Tests for 'zrange1' step.
long zRangeResult5 = db.SortedSetAdd(
"myzset",
[
new("one", 1),
new("two", 2),
new("three", 3)
]
);
SortedSetEntry[] zRangeResult6 = db.SortedSetRangeByRankWithScores("myzset", 0, 1);
Console.WriteLine($"{string.Join(", ", zRangeResult6.Select(b => $"{b.Element}: {b.Score}"))}");
// >>> one: 1, two: 2
// Tests for 'zrange2' step.
long zRangeResult7 = db.SortedSetAdd(
"myzset",
[
new("one", 1),
new("two", 2),
new("three", 3)
]
);
RedisValue[] zRangeResult8 = db.SortedSetRangeByScore(
"myzset",
1,
double.PositiveInfinity,
Exclude.Start,
skip: 1, take: 1
);
Console.WriteLine(string.Join(", ", zRangeResult8));
// >>> three
// Tests for 'zrange3' step.
// Tests for 'zrangebylex' step.
// Tests for 'zrangebyscore' step.
// Tests for 'zrangestore' step.
// Tests for 'zrank' step.
// Tests for 'zrem' step.
// Tests for 'zremrangebylex' step.
// Tests for 'zremrangebyrank' step.
// Tests for 'zremrangebyscore' step.
// Tests for 'zrevrange' step.
// Tests for 'zrevrangebylex' step.
// Tests for 'zrevrangebyscore' step.
// Tests for 'zrevrank' step.
// Tests for 'zscan' step.
// Tests for 'zscore' step.
// Tests for 'zunion' step.
// Tests for 'zunionstore' step.
}
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- when: When, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- when: SortedSetWhen, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- values: SortedSetEntry[], // The members and values to add to the sorted set.
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- values: SortedSetEntry[], // The members and values to add to the sorted set.
- when: When, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
SortedSetRangeByRank(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRankWithScores(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRank(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRankWithScores(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByScore(
- key: RedisKey, // The key of the sorted set.
- start: double, // The minimum score to filter by.
- stop: double, // The maximum score to filter by.
- exclude: Exclude, // Which of start and stop to exclude (defaults to both inclusive).
- order: Order, // The order to sort by (defaults to ascending).
- skip: long, // How many items to skip.
- take: long, // How many items to take.
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRank(
$res5 = $r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);
echo $res5 . PHP_EOL; // >>> 3
$res6 = $r->zrange('myzset', 0, -1);
echo json_encode($res6) . PHP_EOL; // >>> ["one","two","three"]
$res7 = $r->zrange('myzset', 2, 3);
echo json_encode($res7) . PHP_EOL; // >>> ["three"]
$res8 = $r->zrange('myzset', -2, -1);
echo json_encode($res8) . PHP_EOL; // >>> ["two","three"]
<?php
use Predis\Client as PredisClient;
class CmdsSortedSetTest
{
public function testCmdsSortedSet() {
$r = new PredisClient([
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379,
'password' => '',
'database' => 0,
]);
$res1 = $r->zadd('myzset', ['one' => 1]);
echo $res1 . PHP_EOL; // >>> 1
$res2 = $r->zadd('myzset', ['uno' => 1]);
echo $res2 . PHP_EOL; // >>> 1
$res3 = $r->zadd('myzset', ['two' => 2, 'three' => 3]);
echo $res3 . PHP_EOL; // >>> 2
$res4 = $r->zrange('myzset', 0, -1, ['withscores' => true]);
echo json_encode($res4) . PHP_EOL;
// >>> {"one":"1","uno":"1","two":"2","three":"3"}
$res5 = $r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);
echo $res5 . PHP_EOL; // >>> 3
$res6 = $r->zrange('myzset', 0, -1);
echo json_encode($res6) . PHP_EOL; // >>> ["one","two","three"]
$res7 = $r->zrange('myzset', 2, 3);
echo json_encode($res7) . PHP_EOL; // >>> ["three"]
$res8 = $r->zrange('myzset', -2, -1);
echo json_encode($res8) . PHP_EOL; // >>> ["two","three"]
$r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);
$res9 = $r->zrange('myzset', 0, 1, ['withscores' => true]);
echo json_encode($res9) . PHP_EOL; // >>> {"one":"1","two":"2"}
$r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);
$res10 = $r->zrange('myzset', '(1', '+inf', ['byscore' => true, 'limit' => [1, 1]]);
echo json_encode($res10) . PHP_EOL; // >>> ["three"]
}
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- $key: string,
- $membersAndScoresDictionary: array
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- $key: string,
- $start: int|string,
- $stop: int|string,
- ?array $options = null: Any
-
zrange(
res5 = r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])
puts res5 # >>> 3
res6 = r.zrange('myzset', 0, -1)
puts res6.inspect # >>> ["one", "two", "three"]
res7 = r.zrange('myzset', 2, 3)
puts res7.inspect # >>> ["three"]
res8 = r.zrange('myzset', -2, -1)
puts res8.inspect # >>> ["two", "three"]
require 'redis'
r = Redis.new
res1 = r.zadd('myzset', [[1, 'one']])
puts res1 # >>> 1
res2 = r.zadd('myzset', [[1, 'uno']])
puts res2 # >>> 1
res3 = r.zadd('myzset', [[2, 'two'], [3, 'three']])
puts res3 # >>> 2
res4 = r.zrange('myzset', 0, -1, with_scores: true)
puts res4.inspect
# >>> [["one", 1.0], ["uno", 1.0], ["two", 2.0], ["three", 3.0]]
res5 = r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])
puts res5 # >>> 3
res6 = r.zrange('myzset', 0, -1)
puts res6.inspect # >>> ["one", "two", "three"]
res7 = r.zrange('myzset', 2, 3)
puts res7.inspect # >>> ["three"]
res8 = r.zrange('myzset', -2, -1)
puts res8.inspect # >>> ["two", "three"]
r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])
res9 = r.zrange('myzset', 0, 1, with_scores: true)
puts res9.inspect # >>> [["one", 1.0], ["two", 2.0]]
r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])
res10 = r.zrange('myzset', '(1', '+inf', by_score: true, limit: [1, 1])
puts res10.inspect # >>> ["three"]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: String,
- *args: [Float, String], Array<[Float, String]>, // a single [score, member] pair or an array of pairs
- nx: Boolean, // Only add elements that do not already exist
- xx: Boolean, // Only update elements that already exist
- lt: Boolean, // Only update existing elements if the new score is less than the current score
- gt: Boolean, // Only update existing elements if the new score is greater than the current score
- ch: Boolean, // Return the total number of elements changed
- incr: Boolean // ZADD acts like ZINCRBY
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: String,
- start: Integer, // start index
- stop: Integer, // stop index
- by_score: Boolean, // return members by score
- by_lex: Boolean, // return members by lexicographical ordering
- rev: Boolean, // reverse the ordering
- limit: Array, // [offset, count]
- with_scores: Boolean // include scores in output
-
zrange(
if let Ok(res5) = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]) {
let res5: i32 = res5;
println!("{res5}"); // >>> 3
}
if let Ok(res6) = r.zrange("myzset", 0, -1) {
let res6: Vec<String> = res6;
println!("{res6:?}"); // >>> ["one", "two", "three"]
}
if let Ok(res7) = r.zrange("myzset", 2, 3) {
let res7: Vec<String> = res7;
println!("{res7:?}"); // >>> ["three"]
}
if let Ok(res8) = r.zrange("myzset", -2, -1) {
let res8: Vec<String> = res8;
println!("{res8:?}"); // >>> ["two", "three"]
}
mod cmds_sorted_set_tests {
use redis::Commands;
fn run() {
let mut r = match redis::Client::open("redis://127.0.0.1") {
Ok(client) => match client.get_connection() {
Ok(conn) => conn,
Err(e) => {
println!("Failed to connect to Redis: {e}");
return;
}
},
Err(e) => {
println!("Failed to create Redis client: {e}");
return;
}
};
if let Ok(res1) = r.zadd("myzset", "one", 1) {
let res1: i32 = res1;
println!("{res1}"); // >>> 1
}
if let Ok(res2) = r.zadd("myzset", "uno", 1) {
let res2: i32 = res2;
println!("{res2}"); // >>> 1
}
if let Ok(res3) = r.zadd_multiple("myzset", &[(2, "two"), (3, "three")]) {
let res3: i32 = res3;
println!("{res3}"); // >>> 2
}
if let Ok(res4) = r.zrange_withscores("myzset", 0, -1) {
let res4: Vec<(String, f64)> = res4;
println!("{res4:?}");
// >>> [("one", 1.0), ("uno", 1.0), ("two", 2.0), ("three", 3.0)]
}
if let Ok(res5) = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]) {
let res5: i32 = res5;
println!("{res5}"); // >>> 3
}
if let Ok(res6) = r.zrange("myzset", 0, -1) {
let res6: Vec<String> = res6;
println!("{res6:?}"); // >>> ["one", "two", "three"]
}
if let Ok(res7) = r.zrange("myzset", 2, 3) {
let res7: Vec<String> = res7;
println!("{res7:?}"); // >>> ["three"]
}
if let Ok(res8) = r.zrange("myzset", -2, -1) {
let res8: Vec<String> = res8;
println!("{res8:?}"); // >>> ["two", "three"]
}
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]);
if let Ok(res9) = r.zrange_withscores("myzset", 0, 1) {
let res9: Vec<(String, f64)> = res9;
println!("{res9:?}"); // >>> [("one", 1.0), ("two", 2.0)]
}
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]);
if let Ok(res10) = r.zrangebyscore_limit("myzset", "(1", "+inf", 1, 1) {
let res10: Vec<String> = res10;
println!("{res10:?}"); // >>> ["three"]
}
}
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K,
- member: M,
- score: S
-
zadd_multiple(
- key: K,
- items: &'a [(S, M)]
-
zadd_options(
- key: K,
- member: M,
- score: S,
- options: &'a SortedSetAddOptions
-
zadd_multiple_options(
- key: K,
- items: &'a [(S, M)],
- options: &'a SortedSetAddOptions
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K,
- start: isize,
- stop: isize
-
zrange_withscores(
- key: K,
- start: isize,
- stop: isize
-
zrange(
if let Ok(res5) = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]).await {
let res5: i32 = res5;
println!("{res5}"); // >>> 3
}
if let Ok(res6) = r.zrange("myzset", 0, -1).await {
let res6: Vec<String> = res6;
println!("{res6:?}"); // >>> ["one", "two", "three"]
}
if let Ok(res7) = r.zrange("myzset", 2, 3).await {
let res7: Vec<String> = res7;
println!("{res7:?}"); // >>> ["three"]
}
if let Ok(res8) = r.zrange("myzset", -2, -1).await {
let res8: Vec<String> = res8;
println!("{res8:?}"); // >>> ["two", "three"]
}
mod cmds_sorted_set_tests {
use redis::AsyncCommands;
async fn run() {
let mut r = match redis::Client::open("redis://127.0.0.1") {
Ok(client) => match client.get_multiplexed_async_connection().await {
Ok(conn) => conn,
Err(e) => {
println!("Failed to connect to Redis: {e}");
return;
}
},
Err(e) => {
println!("Failed to create Redis client: {e}");
return;
}
};
if let Ok(res1) = r.zadd("myzset", "one", 1).await {
let res1: i32 = res1;
println!("{res1}"); // >>> 1
}
if let Ok(res2) = r.zadd("myzset", "uno", 1).await {
let res2: i32 = res2;
println!("{res2}"); // >>> 1
}
if let Ok(res3) = r.zadd_multiple("myzset", &[(2, "two"), (3, "three")]).await {
let res3: i32 = res3;
println!("{res3}"); // >>> 2
}
if let Ok(res4) = r.zrange_withscores("myzset", 0, -1).await {
let res4: Vec<(String, f64)> = res4;
println!("{res4:?}");
// >>> [("one", 1.0), ("uno", 1.0), ("two", 2.0), ("three", 3.0)]
}
if let Ok(res5) = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]).await {
let res5: i32 = res5;
println!("{res5}"); // >>> 3
}
if let Ok(res6) = r.zrange("myzset", 0, -1).await {
let res6: Vec<String> = res6;
println!("{res6:?}"); // >>> ["one", "two", "three"]
}
if let Ok(res7) = r.zrange("myzset", 2, 3).await {
let res7: Vec<String> = res7;
println!("{res7:?}"); // >>> ["three"]
}
if let Ok(res8) = r.zrange("myzset", -2, -1).await {
let res8: Vec<String> = res8;
println!("{res8:?}"); // >>> ["two", "three"]
}
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]).await;
if let Ok(res9) = r.zrange_withscores("myzset", 0, 1).await {
let res9: Vec<(String, f64)> = res9;
println!("{res9:?}"); // >>> [("one", 1.0), ("two", 2.0)]
}
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]).await;
if let Ok(res10) = r.zrangebyscore_limit("myzset", "(1", "+inf", 1, 1).await {
let res10: Vec<String> = res10;
println!("{res10:?}"); // >>> ["three"]
}
}
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K,
- member: M,
- score: S
-
zadd_multiple(
- key: K,
- items: &'a [(S, M)]
-
zadd_options(
- key: K,
- member: M,
- score: S,
- options: &'a SortedSetAddOptions
-
zadd_multiple_options(
- key: K,
- items: &'a [(S, M)],
- options: &'a SortedSetAddOptions
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K,
- start: isize,
- stop: isize
-
zrange_withscores(
- key: K,
- start: isize,
- stop: isize
-
zrange(
The following example using WITHSCORES shows how the command returns always an array, but this time, populated with element_1, score_1, element_2, score_2, ..., element_N, score_N.
res = r.zadd("myzset", {"one": 1, "two":2, "three":3})
res = r.zrange("myzset", 0, 1, withscores=True)
print(res)
# >>> [('one', 1.0), ('two', 2.0)]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- name: KeyT,
- mapping: Mapping[AnyKeyT, EncodableT],
- nx: bool = False,
- xx: bool = False,
- ch: bool = False,
- incr: bool = False,
- gt: bool = False,
- lt: bool = False
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- name: KeyT,
- start: EncodableT,
- end: EncodableT,
- desc: bool = False,
- withscores: bool = False,
- score_cast_func: Union[type, Callable] = float,
- byscore: bool = False,
- bylex: bool = False,
- offset: Optional[int] = None,
- num: Optional[int] = None
-
zrange(
const val9 = await client.zAdd("myzset", [
{ value: 'one', score: 1 },
{ value: 'two', score: 2 },
{ value: 'three', score: 3 }
]);
console.log(val9);
// returns 3
const val10 = await client.zRangeWithScores('myzset', 0, 1);
console.log(val10);
// returns [{value: 'one', score: 1}, {value: 'two', score: 2}]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
ZADD(
- key: RedisArgument,
- members: SortedSetMember | Array<SortedSetMember>,
- options?: ZAddOptions
-
ZADD(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
ZRANGE(
- key: RedisArgument,
- min: RedisArgument | number,
- max: RedisArgument | number,
- options?: ZRangeOptions
-
ZRANGE_WITHSCORES(
- ...args: Parameters<typeof ZRANGE.parseCommand>
-
ZRANGE(
await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');
const res9 = await redis.zrange('myzset', 0, 1, 'WITHSCORES');
console.log(res9); // >>> ['one', '1', 'two', '2']
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [key
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [, key
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- withscores: "WITHSCORES",
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- offsetCountToken: "LIMIT",
- offset: number | string,
- count: number | string,
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- offsetCountToken: "LIMIT",
- offset: number | string,
- count: number | string,
- withscores: "WITHSCORES",
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- rev: "REV",
- callback?: Callback<string[]>
-
zrange(
Map<String, Double> zRangeExampleParams2 = new HashMap<>();
zRangeExampleParams2.put("one", 1.0);
zRangeExampleParams2.put("two", 2.0);
zRangeExampleParams2.put("three", 3.0);
long zRangeResult5 = jedis.zadd("myzset", zRangeExampleParams2);
System.out.println(zRangeResult5); // >>> 3
List<Tuple> zRangeResult6 = jedis.zrangeWithScores("myzset", new ZRangeParams(0, 1));
for (Tuple item: zRangeResult6) {
System.out.println("Element: " + item.getElement() + ", Score: " + item.getScore());
}
// >>> Element: one, Score: 1.0
// >>> Element: two, Score: 2.0
-
Deletes one or more keys.
-
del(
- keys: byte[]...
-
del(
- key: byte[]
-
del(
- keys: String...
-
del(
- key: String
-
del(
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: byte[],
- score: double,
- member: byte[]
-
zadd(
- key: byte[],
- score: double,
- params: byte[] member final ZAddParams
-
zadd(
- key: byte[],
- scoreMembers: Map<byte[], Double>
-
zadd(
- key: byte[],
- scoreMembers: Map<byte[], Double>,
- params: ZAddParams
-
zadd(
- key: String,
- score: double,
- member: String
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrangeWithScores(
- key: byte[],
- start: long,
- stop: long
-
zrangeWithScores(
- key: byte[],
- zRangeParams: ZRangeParams
-
zrange(
- key: String,
- start: long,
- stop: long
-
zrangeWithScores(
- key: String,
- start: long,
- stop: long
-
zrange(
- key: String,
- zRangeParams: ZRangeParams
-
zrangeWithScores(
CompletableFuture<Void> zRange2Example = asyncCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.thenCompose(res9 -> {
return asyncCommands.zrangeWithScores("myzset", 0, 1);
}).thenAccept(res10 -> {
System.out.println(res10);
// >>> [ScoredValue[1.000000, one], ScoredValue[2.000000, two]]
}).toCompletableFuture();
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K, // the ke.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- scoresAndValues: Object...
-
zadd(
- key: K, // the ke.
- scoredValues: ScoredValue<V>... // the scored values.
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- scoresAndValues: Object...
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
- channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
Mono<Void> zRange2Example = reactiveCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.then(reactiveCommands.zrangeWithScores("myzset", 0, 1).collectList())
.doOnNext(res9 -> {
System.out.println(res9);
// >>> [ScoredValue[1.000000, one], ScoredValue[2.000000, two]]
})
.then();
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K, // the ke.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- scoresAndValues: Object...
-
zadd(
- key: K, // the ke.
- scoredValues: ScoredValue<V>... // the scored values.
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- scoresAndValues: Object...
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
- channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
zRangeResult5, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "one", Score: 1},
redis.Z{Member: "two", Score: 2},
redis.Z{Member: "three", Score: 3},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult5) // >>> 3
zRangeResult6, err := rdb.ZRangeWithScores(ctx, "myzset", 0, 1).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult6) // >>> [{1 one} {2 two}]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
ZAdd(
- ctx: context.Context,
- key: string,
- members: ...Z
-
ZAdd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
ZRange(
- ctx: context.Context,
- key: string,
- start: Any,
- stop: int64
-
ZRangeWithScores(
- ctx: context.Context,
- key: string,
- start: Any,
- stop: int64
-
ZRange(
long zRangeResult5 = db.SortedSetAdd(
"myzset",
[
new("one", 1),
new("two", 2),
new("three", 3)
]
);
SortedSetEntry[] zRangeResult6 = db.SortedSetRangeByRankWithScores("myzset", 0, 1);
Console.WriteLine($"{string.Join(", ", zRangeResult6.Select(b => $"{b.Element}: {b.Score}"))}");
// >>> one: 1, two: 2
-
Deletes one or more keys.
-
KeyDelete(
- key: RedisKey,
- flags: CommandFlags // The flags to use for this operation.
-
KeyDelete(
- keys: RedisKey[], // The keys to delete.
- flags: CommandFlags // The flags to use for this operation.
-
KeyDelete(
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- when: When, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- when: SortedSetWhen, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- values: SortedSetEntry[], // The members and values to add to the sorted set.
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- values: SortedSetEntry[], // The members and values to add to the sorted set.
- when: When, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
SortedSetRangeByRank(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRankWithScores(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRank(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRankWithScores(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByScore(
- key: RedisKey, // The key of the sorted set.
- start: double, // The minimum score to filter by.
- stop: double, // The maximum score to filter by.
- exclude: Exclude, // Which of start and stop to exclude (defaults to both inclusive).
- order: Order, // The order to sort by (defaults to ascending).
- skip: long, // How many items to skip.
- take: long, // How many items to take.
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRank(
$r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);
$res9 = $r->zrange('myzset', 0, 1, ['withscores' => true]);
echo json_encode($res9) . PHP_EOL; // >>> {"one":"1","two":"2"}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- $key: string,
- $membersAndScoresDictionary: array
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- $key: string,
- $start: int|string,
- $stop: int|string,
- ?array $options = null: Any
-
zrange(
r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])
res9 = r.zrange('myzset', 0, 1, with_scores: true)
puts res9.inspect # >>> [["one", 1.0], ["two", 2.0]]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: String,
- *args: [Float, String], Array<[Float, String]>, // a single [score, member] pair or an array of pairs
- nx: Boolean, // Only add elements that do not already exist
- xx: Boolean, // Only update elements that already exist
- lt: Boolean, // Only update existing elements if the new score is less than the current score
- gt: Boolean, // Only update existing elements if the new score is greater than the current score
- ch: Boolean, // Return the total number of elements changed
- incr: Boolean // ZADD acts like ZINCRBY
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: String,
- start: Integer, // start index
- stop: Integer, // stop index
- by_score: Boolean, // return members by score
- by_lex: Boolean, // return members by lexicographical ordering
- rev: Boolean, // reverse the ordering
- limit: Array, // [offset, count]
- with_scores: Boolean // include scores in output
-
zrange(
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]);
if let Ok(res9) = r.zrange_withscores("myzset", 0, 1) {
let res9: Vec<(String, f64)> = res9;
println!("{res9:?}"); // >>> [("one", 1.0), ("two", 2.0)]
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K,
- member: M,
- score: S
-
zadd_multiple(
- key: K,
- items: &'a [(S, M)]
-
zadd_options(
- key: K,
- member: M,
- score: S,
- options: &'a SortedSetAddOptions
-
zadd_multiple_options(
- key: K,
- items: &'a [(S, M)],
- options: &'a SortedSetAddOptions
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K,
- start: isize,
- stop: isize
-
zrange_withscores(
- key: K,
- start: isize,
- stop: isize
-
zrange(
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]).await;
if let Ok(res9) = r.zrange_withscores("myzset", 0, 1).await {
let res9: Vec<(String, f64)> = res9;
println!("{res9:?}"); // >>> [("one", 1.0), ("two", 2.0)]
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K,
- member: M,
- score: S
-
zadd_multiple(
- key: K,
- items: &'a [(S, M)]
-
zadd_options(
- key: K,
- member: M,
- score: S,
- options: &'a SortedSetAddOptions
-
zadd_multiple_options(
- key: K,
- items: &'a [(S, M)],
- options: &'a SortedSetAddOptions
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K,
- start: isize,
- stop: isize
-
zrange_withscores(
- key: K,
- start: isize,
- stop: isize
-
zrange(
This example shows how to query the sorted set by score, excluding the value 1 and up to infinity, returning only the second element of the result:
res = r.zadd("myzset", {"one": 1, "two":2, "three":3})
res = r.zrange("myzset", 2, 3, byscore=True, offset=1, num=1)
print(res)
# >>> ['three']
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- name: KeyT,
- mapping: Mapping[AnyKeyT, EncodableT],
- nx: bool = False,
- xx: bool = False,
- ch: bool = False,
- incr: bool = False,
- gt: bool = False,
- lt: bool = False
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- name: KeyT,
- start: EncodableT,
- end: EncodableT,
- desc: bool = False,
- withscores: bool = False,
- score_cast_func: Union[type, Callable] = float,
- byscore: bool = False,
- bylex: bool = False,
- offset: Optional[int] = None,
- num: Optional[int] = None
-
zrange(
const val11 = await client.zAdd("myzset", [
{ value: 'one', score: 1 },
{ value: 'two', score: 2 },
{ value: 'three', score: 3 }
]);
console.log(val11);
// returns 3
const val12 = await client.zRange('myzset', 2, 3, { BY: 'SCORE', LIMIT: { offset: 1, count: 1 } });
console.log(val12);
// >>> ['three']
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
ZADD(
- key: RedisArgument,
- members: SortedSetMember | Array<SortedSetMember>,
- options?: ZAddOptions
-
ZADD(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
ZRANGE(
- key: RedisArgument,
- min: RedisArgument | number,
- max: RedisArgument | number,
- options?: ZRangeOptions
-
ZRANGE_WITHSCORES(
- ...args: Parameters<typeof ZRANGE.parseCommand>
-
ZRANGE(
await redis.zadd('myzset', 1, 'one', 2, 'two', 3, 'three');
const res10 = await redis.zrange('myzset', '(1', '+inf', 'BYSCORE', 'LIMIT', 1, 1);
console.log(res10); // >>> ['three']
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [key
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [, key
-
zadd(
- ...args: [, key
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- withscores: "WITHSCORES",
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- offsetCountToken: "LIMIT",
- offset: number | string,
- count: number | string,
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- offsetCountToken: "LIMIT",
- offset: number | string,
- count: number | string,
- withscores: "WITHSCORES",
- callback?: Callback<string[]>
-
zrange(
- key: RedisKey,
- min: string | Buffer | number,
- max: string | Buffer | number,
- rev: "REV",
- callback?: Callback<string[]>
-
zrange(
Map<String, Double> zRangeExampleParams3 = new HashMap<>();
zRangeExampleParams3.put("one", 1.0);
zRangeExampleParams3.put("two", 2.0);
zRangeExampleParams3.put("three", 3.0);
long zRangeResult7 = jedis.zadd("myzset", zRangeExampleParams3);
System.out.println(zRangeResult7); // >>> 3
List<String> zRangeResult8 = jedis.zrangeByScore("myzset", "(1", "+inf", 1, 1);
System.out.println(String.join(", ", zRangeResult8)); // >>> three
-
Deletes one or more keys.
-
del(
- keys: byte[]...
-
del(
- key: byte[]
-
del(
- keys: String...
-
del(
- key: String
-
del(
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: byte[],
- score: double,
- member: byte[]
-
zadd(
- key: byte[],
- score: double,
- params: byte[] member final ZAddParams
-
zadd(
- key: byte[],
- scoreMembers: Map<byte[], Double>
-
zadd(
- key: byte[],
- scoreMembers: Map<byte[], Double>,
- params: ZAddParams
-
zadd(
- key: String,
- score: double,
- member: String
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrangeWithScores(
- key: byte[],
- start: long,
- stop: long
-
zrangeWithScores(
- key: byte[],
- zRangeParams: ZRangeParams
-
zrange(
- key: String,
- start: long,
- stop: long
-
zrangeWithScores(
- key: String,
- start: long,
- stop: long
-
zrange(
- key: String,
- zRangeParams: ZRangeParams
-
zrangeWithScores(
CompletableFuture<Void> zRange3Example = asyncCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.thenCompose(res11 -> {
return asyncCommands.zrangebyscore("myzset",
Range.from(Range.Boundary.excluding(1d), Range.Boundary.unbounded()),
Limit.create(1, 1));
}).thenAccept(res12 -> {
System.out.println(res12); // >>> [three]
}).toCompletableFuture();
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K, // the ke.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- scoresAndValues: Object...
-
zadd(
- key: K, // the ke.
- scoredValues: ScoredValue<V>... // the scored values.
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- scoresAndValues: Object...
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
- channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
Mono<Void> zRange3Example = reactiveCommands.zadd("myzset",
ScoredValue.just(1d, "one"), ScoredValue.just(2d, "two"), ScoredValue.just(3d, "three"))
.then(reactiveCommands.zrangebyscore("myzset",
Range.from(Range.Boundary.excluding(1d), Range.Boundary.unbounded()),
Limit.create(1, 1)).collectList())
.doOnNext(res10 -> {
System.out.println(res10); // >>> [three]
})
.then();
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K, // the ke.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- scoresAndValues: Object...
-
zadd(
- key: K, // the ke.
- scoredValues: ScoredValue<V>... // the scored values.
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- score: double,
- member: V
-
zadd(
- key: K, // the ke.
- zAddArgs: ZAddArgs, // arguments for zadd.
- scoresAndValues: Object...
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
- channel: ValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrangeWithScores(
- channel: ScoredValueStreamingChannel<V>, // streaming channel that receives a call for every value.
- key: K, // the key.
- start: long, // the start.
- stop: long // the stop.
-
zrange(
zRangeResult7, err := rdb.ZAdd(ctx, "myzset",
redis.Z{Member: "one", Score: 1},
redis.Z{Member: "two", Score: 2},
redis.Z{Member: "three", Score: 3},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult7) // >>> 3
zRangeResult8, err := rdb.ZRangeArgs(ctx,
redis.ZRangeArgs{
Key: "myzset",
ByScore: true,
Start: "(1",
Stop: "+inf",
Offset: 1,
Count: 1,
},
).Result()
if err != nil {
panic(err)
}
fmt.Println(zRangeResult8) // >>> [three]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
ZAdd(
- ctx: context.Context,
- key: string,
- members: ...Z
-
ZAdd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
ZRange(
- ctx: context.Context,
- key: string,
- start: Any,
- stop: int64
-
ZRangeWithScores(
- ctx: context.Context,
- key: string,
- start: Any,
- stop: int64
-
ZRange(
long zRangeResult7 = db.SortedSetAdd(
"myzset",
[
new("one", 1),
new("two", 2),
new("three", 3)
]
);
RedisValue[] zRangeResult8 = db.SortedSetRangeByScore(
"myzset",
1,
double.PositiveInfinity,
Exclude.Start,
skip: 1, take: 1
);
Console.WriteLine(string.Join(", ", zRangeResult8));
// >>> three
-
Deletes one or more keys.
-
KeyDelete(
- key: RedisKey,
- flags: CommandFlags // The flags to use for this operation.
-
KeyDelete(
- keys: RedisKey[], // The keys to delete.
- flags: CommandFlags // The flags to use for this operation.
-
KeyDelete(
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- when: When, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- member: RedisValue,
- score: double,
- when: SortedSetWhen, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- values: SortedSetEntry[], // The members and values to add to the sorted set.
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
- key: RedisKey, // The key of the sorted set.
- values: SortedSetEntry[], // The members and values to add to the sorted set.
- when: When, // What conditions to add the element under (defaults to always).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetAdd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
SortedSetRangeByRank(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRankWithScores(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRank(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRankWithScores(
- key: RedisKey, // The key of the sorted set.
- start: long, // The start index to get.
- stop: long, // The stop index to get.
- order: Order, // The order to sort by (defaults to ascending).
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByScore(
- key: RedisKey, // The key of the sorted set.
- start: double, // The minimum score to filter by.
- stop: double, // The maximum score to filter by.
- exclude: Exclude, // Which of start and stop to exclude (defaults to both inclusive).
- order: Order, // The order to sort by (defaults to ascending).
- skip: long, // How many items to skip.
- take: long, // How many items to take.
- flags: CommandFlags // The flags to use for this operation.
-
SortedSetRangeByRank(
$r->zadd('myzset', ['one' => 1, 'two' => 2, 'three' => 3]);
$res10 = $r->zrange('myzset', '(1', '+inf', ['byscore' => true, 'limit' => [1, 1]]);
echo json_encode($res10) . PHP_EOL; // >>> ["three"]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- $key: string,
- $membersAndScoresDictionary: array
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- $key: string,
- $start: int|string,
- $stop: int|string,
- ?array $options = null: Any
-
zrange(
r.zadd('myzset', [[1, 'one'], [2, 'two'], [3, 'three']])
res10 = r.zrange('myzset', '(1', '+inf', by_score: true, limit: [1, 1])
puts res10.inspect # >>> ["three"]
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: String,
- *args: [Float, String], Array<[Float, String]>, // a single [score, member] pair or an array of pairs
- nx: Boolean, // Only add elements that do not already exist
- xx: Boolean, // Only update elements that already exist
- lt: Boolean, // Only update existing elements if the new score is less than the current score
- gt: Boolean, // Only update existing elements if the new score is greater than the current score
- ch: Boolean, // Return the total number of elements changed
- incr: Boolean // ZADD acts like ZINCRBY
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: String,
- start: Integer, // start index
- stop: Integer, // stop index
- by_score: Boolean, // return members by score
- by_lex: Boolean, // return members by lexicographical ordering
- rev: Boolean, // reverse the ordering
- limit: Array, // [offset, count]
- with_scores: Boolean // include scores in output
-
zrange(
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]);
if let Ok(res10) = r.zrangebyscore_limit("myzset", "(1", "+inf", 1, 1) {
let res10: Vec<String> = res10;
println!("{res10:?}"); // >>> ["three"]
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K,
- member: M,
- score: S
-
zadd_multiple(
- key: K,
- items: &'a [(S, M)]
-
zadd_options(
- key: K,
- member: M,
- score: S,
- options: &'a SortedSetAddOptions
-
zadd_multiple_options(
- key: K,
- items: &'a [(S, M)],
- options: &'a SortedSetAddOptions
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K,
- start: isize,
- stop: isize
-
zrange_withscores(
- key: K,
- start: isize,
- stop: isize
-
zrange(
let _: Result<i32, _> = r.zadd_multiple("myzset", &[(1, "one"), (2, "two"), (3, "three")]).await;
if let Ok(res10) = r.zrangebyscore_limit("myzset", "(1", "+inf", 1, 1).await {
let res10: Vec<String> = res10;
println!("{res10:?}"); // >>> ["three"]
}
-
ZADD ( @write , @sortedset , @fast )Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
-
zadd(
- key: K,
- member: M,
- score: S
-
zadd_multiple(
- key: K,
- items: &'a [(S, M)]
-
zadd_options(
- key: K,
- member: M,
- score: S,
- options: &'a SortedSetAddOptions
-
zadd_multiple_options(
- key: K,
- items: &'a [(S, M)],
- options: &'a SortedSetAddOptions
-
zadd(
-
ZRANGE ( @read , @sortedset , @slow )Returns members in a sorted set within a range of indexes.
-
zrange(
- key: K,
- start: isize,
- stop: isize
-
zrange_withscores(
- key: K,
- start: isize,
- stop: isize
-
zrange(
Details
Common behavior and options
The order of elements is from the lowest to the highest score. Elements with the same score are ordered lexicographically.
The optional REV argument reverses the ordering, so elements are ordered from highest to lowest score, and score ties are resolved by reverse lexicographical ordering.
The optional LIMIT argument can be used to obtain a sub-range from the matching elements (similar to SELECT LIMIT offset, count in SQL).
A negative <count> returns all elements from the <offset>. Keep in mind that if <offset> is large, the sorted set needs to be traversed for <offset> elements before getting to the elements to return, which can add up to O(N) time complexity.
The optional WITHSCORES argument supplements the command's reply with the scores of elements returned. The returned list contains value1,score1,...,valueN,scoreN instead of value1,...,valueN. Client libraries are free to return a more appropriate data type (suggestion: an array with (value, score) arrays/tuples).
Index ranges
By default, the command performs an index range query. The <start> and <stop> arguments represent zero-based indexes, where 0 is the first element, 1 is the next element, and so on. These arguments specify an inclusive range, so for example, ZRANGE myzset 0 1 will return both the first and the second element of the sorted set.
The indexes can also be negative numbers indicating offsets from the end of the sorted set, with -1 being the last element of the sorted set, -2 the penultimate element, and so on.
Out of range indexes do not produce an error.
If <start> is greater than either the end index of the sorted set or <stop>, an empty list is returned.
If <stop> is greater than the end index of the sorted set, Redis will use the last element of the sorted set.
Score ranges
When the BYSCORE option is provided, the command behaves like ZRANGEBYSCORE and returns the range of elements from the sorted set having scores equal or between <start> and <stop>.
<start> and <stop> can be -inf and +inf, denoting the negative and positive infinities, respectively. This means that you are not required to know the highest or lowest score in the sorted set to get all elements from or up to a certain score.
By default, the score intervals specified by <start> and <stop> are closed (inclusive).
It is possible to specify an open interval (exclusive) by prefixing the score
with the character (.
For example:
ZRANGE zset (1 5 BYSCORE
Will return all elements with 1 < score <= 5 while:
ZRANGE zset (5 (10 BYSCORE
Will return all the elements with 5 < score < 10 (5 and 10 excluded).
Reverse ranges
Using the REV option reverses the sorted set, with index 0 as the element with the highest score.
By default, <start> must be less than or equal to <stop> to return anything.
However, if the BYSCORE, or BYLEX options are selected, the <start> is the highest score to consider, and <stop> is the lowest score to consider, therefore <start> must be greater than or equal to <stop> in order to return anything.
For example:
ZRANGE zset 5 10 REV
Will return the elements between index 5 and 10 in the reversed index.
ZRANGE zset 10 5 REV BYSCORE
Will return all elements with scores less than 10 and greater than 5.
Lexicographical ranges
When the BYLEX option is used, the command behaves like ZRANGEBYLEX and returns the range of elements from the sorted set between the <start> and <stop> lexicographical closed range intervals.
Note that lexicographical ordering relies on all elements having the same score. The reply is unspecified when the elements have different scores.
Valid <start> and <stop> must start with ( or [, in order to specify
whether the range interval is exclusive or inclusive, respectively.
The special values of + or - for <start> and <stop> mean positive and negative infinite strings, respectively, so for instance the command ZRANGE myzset - + BYLEX is guaranteed to return all the elements in the sorted set, providing that all the elements have the same score.
The REV options reverses the order of the <start> and <stop> elements, where <start> must be lexicographically greater than <stop> to produce a non-empty result.
Lexicographical comparison of strings
Strings are compared as a binary array of bytes. Because of how the ASCII character set is specified, this means that usually this also have the effect of comparing normal ASCII characters in an obvious dictionary way. However, this is not true if non-plain ASCII strings are used (for example, utf8 strings).
However, the user can apply a transformation to the encoded string so that the first part of the element inserted in the sorted set will compare as the user requires for the specific application. For example, if I want to add strings that will be compared in a case-insensitive way, but I still want to retrieve the real case when querying, I can add strings in the following way:
ZADD autocomplete 0 foo:Foo 0 bar:BAR 0 zap:zap
Because of the first normalized part in every element (before the colon character), we are forcing a given comparison. However, after the range is queried using ZRANGE ... BYLEX, the application can display to the user the second part of the string, after the colon.
The binary nature of the comparison allows to use sorted sets as a general purpose index, for example, the first part of the element can be a 64-bit big-endian number. Since big-endian numbers have the most significant bytes in the initial positions, the binary comparison will match the numerical comparison of the numbers. This can be used in order to implement range queries on 64-bit values. As in the example below, after the first 8 bytes, we can store the value of the element we are indexing.
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Return information
History
- Starting with Redis version 6.2.0: Added the
REV,BYSCORE,BYLEXandLIMIToptions.