BZMOVE
BZMOVE source destination <MIN | MAX> timeout [COUNT count]
- Available since:
- Redis Open Source 8.12.0
- Time complexity:
- O(K*(log(N)+log(M))) where K is the number of moved members and N and M are the source and destination sizes.
- ACL categories:
-
@write,@sortedset,@slow,@blocking, - Compatibility:
- Redis Software and Redis Cloud compatibility
BZMOVE is the blocking variant of ZMOVE for
moving lowest-scoring or highest-scoring members between sorted sets.
When source contains members, it behaves like ZMOVE with the same MIN or
MAX selector and optional COUNT.
When source does not exist, the connection waits until at least one member
becomes available or the timeout expires. When members become available, it
moves up to count members without waiting for a full batch. If the timeout
expires first, it returns null. Changes to destination do not unblock the
connection. BYSCORE is not supported.
Moved members retain their source scores. If a member already exists in
destination, that score is overwritten. Other destination members are
retained. Redis creates destination if needed and deletes source when its
last member is moved. Existing expiration times are preserved; a newly created
destination has no expiration.
If both arguments name the same sorted set or the same nonexistent key, the
command returns null without moving members or blocking. Inside a
MULTI/EXEC
transaction or a script, the command does not block. If no member is available,
it returns null.
A source key of the wrong type causes a WRONGTYPE error immediately.
The destination type is checked when members are available to move. If a
blocked client wakes and destination holds another type, the command returns
WRONGTYPE and leaves the source members unchanged.
In Redis Open Source Cluster, both keys must be in the same hash slot. See multi-key operations.
Required arguments
source
The key of the sorted set to move members from. This is the only key the command blocks on.
destination
The key of the sorted set to move members to.
MIN | MAX
Move the members with the lowest scores (MIN) or highest scores (MAX).
MIN returns members in ascending score order, and MAX in descending score
order. Equal scores follow the corresponding lexicographical member order.
timeout
The maximum time to block, in seconds. This is a non-negative double, so
fractional seconds are allowed. A timeout of 0 blocks indefinitely.
Optional arguments
COUNT count
Move at most count available members. The default is 1. count must be a
positive integer. Zero and negative counts return
ERR count should be greater than 0 before moving members or blocking.
Examples
Move the available members without waiting for a full batch:
> ZADD ready:{example} 1 first 2 second
(integer) 2
> BZMOVE ready:{example} processing:{example} MIN 1 COUNT 3
1) 1) "first"
2) "1"
2) 1) "second"
2) "2"
> BZMOVE ready:{example} processing:{example} MIN 0 COUNT 0
(error) ERR count should be greater than 0res7 = r.zadd("ready:{example}", {"first": 1, "second": 2})
print(res7)
# >>> 2
res8 = r.bzmove("ready:{example}", "processing:{example}", 1, min=True, count=3)
print(res8)
# >>> [['first', 1.0], ['second', 2.0]]
import redis
r = redis.Redis(decode_responses=True)
res1 = r.zadd("scores:{example}", {"one": 1, "two": 2, "three": 3})
print(res1)
# >>> 3
res2 = r.zadd("moved:{example}", {"one": 99, "retained": 100})
print(res2)
# >>> 2
res3 = r.zmove("scores:{example}", "moved:{example}", min=True)
print(res3)
# >>> [['one', 1.0]]
res4 = r.zmove("scores:{example}", "moved:{example}", max=True)
print(res4)
# >>> [['three', 3.0]]
res5 = r.zrange("moved:{example}", 0, -1, withscores=True)
print(res5)
# >>> [('one', 1.0), ('three', 3.0), ('retained', 100.0)]
res6 = r.zrange("scores:{example}", 0, -1, withscores=True)
print(res6)
# >>> [('two', 2.0)]
res7 = r.zadd("ready:{example}", {"first": 1, "second": 2})
print(res7)
# >>> 2
res8 = r.bzmove("ready:{example}", "processing:{example}", 1, min=True, count=3)
print(res8)
# >>> [['first', 1.0], ['second', 2.0]]
res9 = r.zadd(
"bookmarks:{user:42}",
{"bookmark:a": 1699999998, "bookmark:b": 1699999999, "bookmark:c": 1700000000},
)
print(res9)
# >>> 3
res10 = r.zmove(
"bookmarks:{user:42}",
"batch:{user:42}:001",
byscore=("-inf", "(1700000000"),
count=500,
)
print(res10)
# >>> [['bookmark:a', 1699999998.0], ['bookmark:b', 1699999999.0]]
res11 = r.zrange("bookmarks:{user:42}", 0, -1, withscores=True)
print(res11)
# >>> [('bookmark:c', 1700000000.0)]
res12 = r.zmove(
"bookmarks:{user:42}",
"batch:{user:42}:002",
byscore=("-inf", "(1700000000"),
count=500,
)
print(res12)
# >>> None
res13 = r.zadd("source:{example}", {"one": 1, "two": 2})
print(res13)
# >>> 2
res14 = r.zadd("destination:{example}", {"two": 99, "retained": 100})
print(res14)
# >>> 2
res15 = r.zmovemember("source:{example}", "destination:{example}", ["missing", "two", "two"])
print(res15)
# >>> [['two', 2.0]]
res16 = r.zrange("source:{example}", 0, -1, withscores=True)
print(res16)
# >>> [('one', 1.0)]
res17 = r.zrange("destination:{example}", 0, -1, withscores=True)
print(res17)
# >>> [('two', 2.0), ('retained', 100.0)]
res18 = r.zadd("source:{conditional}", {"existing": 1, "new": 2})
print(res18)
# >>> 2
res19 = r.zadd("destination:{conditional}", {"existing": 99})
print(res19)
# >>> 1
res20 = r.zmovemember(
"source:{conditional}", "destination:{conditional}", ["existing", "new"], nx=True
)
print(res20)
# >>> [['new', 2.0]]
res21 = r.zscore("source:{conditional}", "existing")
print(res21)
# >>> 1.0
res22 = r.zmovemember(
"source:{conditional}", "destination:{conditional}", ["existing"], xx=True
)
print(res22)
# >>> [['existing', 1.0]]
res23 = r.zrange("destination:{conditional}", 0, -1, withscores=True)
print(res23)
# >>> [('existing', 1.0), ('new', 2.0)]
const res7 = await client.zAdd('ready:{example}', [
{ score: 1, value: 'first' },
{ score: 2, value: 'second' }
]);
console.log(res7); // >>> 2
const res8 = await client.bzMove('ready:{example}', 'processing:{example}', 'MIN', 1, { COUNT: 3 });
console.log(res8); // >>> [ { value: 'first', score: 1 }, { value: 'second', score: 2 } ]
import assert from 'node:assert';
import { createClient } from 'redis';
const client = createClient();
await client.connect();
const res1 = await client.zAdd('scores:{example}', [
{ score: 1, value: 'one' },
{ score: 2, value: 'two' },
{ score: 3, value: 'three' }
]);
console.log(res1); // >>> 3
const res2 = await client.zAdd('moved:{example}', [
{ score: 99, value: 'one' },
{ score: 100, value: 'retained' }
]);
console.log(res2); // >>> 2
const res3 = await client.zMove('scores:{example}', 'moved:{example}', 'MIN');
console.log(res3); // >>> [ { value: 'one', score: 1 } ]
const res4 = await client.zMove('scores:{example}', 'moved:{example}', 'MAX');
console.log(res4); // >>> [ { value: 'three', score: 3 } ]
const res5 = await client.zRangeWithScores('moved:{example}', 0, -1);
console.log(res5);
// >>> [ { value: 'one', score: 1 }, { value: 'three', score: 3 }, { value: 'retained', score: 100 } ]
const res6 = await client.zRangeWithScores('scores:{example}', 0, -1);
console.log(res6); // >>> [ { value: 'two', score: 2 } ]
const res7 = await client.zAdd('ready:{example}', [
{ score: 1, value: 'first' },
{ score: 2, value: 'second' }
]);
console.log(res7); // >>> 2
const res8 = await client.bzMove('ready:{example}', 'processing:{example}', 'MIN', 1, { COUNT: 3 });
console.log(res8); // >>> [ { value: 'first', score: 1 }, { value: 'second', score: 2 } ]
const res9 = await client.zAdd('bookmarks:{user:42}', [
{ score: 1699999998, value: 'bookmark:a' },
{ score: 1699999999, value: 'bookmark:b' },
{ score: 1700000000, value: 'bookmark:c' }
]);
console.log(res9); // >>> 3
const res10 = await client.zMove(
'bookmarks:{user:42}',
'batch:{user:42}:001',
{ min: '-inf', max: '(1700000000' },
{ COUNT: 500 }
);
console.log(res10);
// >>> [ { value: 'bookmark:a', score: 1699999998 }, { value: 'bookmark:b', score: 1699999999 } ]
const res11 = await client.zRangeWithScores('bookmarks:{user:42}', 0, -1);
console.log(res11); // >>> [ { value: 'bookmark:c', score: 1700000000 } ]
const res12 = await client.zMove(
'bookmarks:{user:42}',
'batch:{user:42}:002',
{ min: '-inf', max: '(1700000000' },
{ COUNT: 500 }
);
console.log(res12); // >>> null
const res13 = await client.zAdd('source:{example}', [
{ score: 1, value: 'one' },
{ score: 2, value: 'two' }
]);
console.log(res13); // >>> 2
const res14 = await client.zAdd('destination:{example}', [
{ score: 99, value: 'two' },
{ score: 100, value: 'retained' }
]);
console.log(res14); // >>> 2
const res15 = await client.zMoveMember('source:{example}', 'destination:{example}', ['missing', 'two', 'two']);
console.log(res15); // >>> [ { value: 'two', score: 2 } ]
const res16 = await client.zRangeWithScores('source:{example}', 0, -1);
console.log(res16); // >>> [ { value: 'one', score: 1 } ]
const res17 = await client.zRangeWithScores('destination:{example}', 0, -1);
console.log(res17); // >>> [ { value: 'two', score: 2 }, { value: 'retained', score: 100 } ]
const res18 = await client.zAdd('source:{conditional}', [
{ score: 1, value: 'existing' },
{ score: 2, value: 'new' }
]);
console.log(res18); // >>> 2
const res19 = await client.zAdd('destination:{conditional}', { score: 99, value: 'existing' });
console.log(res19); // >>> 1
const res20 = await client.zMoveMember(
'source:{conditional}', 'destination:{conditional}', ['existing', 'new'], { condition: 'NX' }
);
console.log(res20); // >>> [ { value: 'new', score: 2 } ]
const res21 = await client.zScore('source:{conditional}', 'existing');
console.log(res21); // >>> 1
const res22 = await client.zMoveMember(
'source:{conditional}', 'destination:{conditional}', 'existing', { condition: 'XX' }
);
console.log(res22); // >>> [ { value: 'existing', score: 1 } ]
const res23 = await client.zRangeWithScores('destination:{conditional}', 0, -1);
console.log(res23); // >>> [ { value: 'existing', score: 1 }, { value: 'new', score: 2 } ]
await client.close();
long res7 = jedis.zadd("ready:{example}", new HashMap<String, Double>() {{
put("first", 1d);
put("second", 2d);
}});
System.out.println(res7); // >>> 2
List<Tuple> res8 = jedis.bzmove("ready:{example}", "processing:{example}", SortedSetOption.MIN, 1, 3);
System.out.println(res8); // >>> [[first,1.0], [second,2.0]]
package io.redis.examples;
import redis.clients.jedis.RedisClient;
import redis.clients.jedis.args.SortedSetOption;
import redis.clients.jedis.params.ZMoveMemberParams;
import redis.clients.jedis.resps.Tuple;
public class CmdsZmoveExample {
public void run() {
RedisClient jedis = RedisClient.create("redis://localhost:6379");
long res1 = jedis.zadd("scores:{example}", new HashMap<String, Double>() {{
put("one", 1d);
put("two", 2d);
put("three", 3d);
}});
System.out.println(res1); // >>> 3
long res2 = jedis.zadd("moved:{example}", new HashMap<String, Double>() {{
put("one", 99d);
put("retained", 100d);
}});
System.out.println(res2); // >>> 2
List<Tuple> res3 = jedis.zmove("scores:{example}", "moved:{example}", SortedSetOption.MIN);
System.out.println(res3); // >>> [[one,1.0]]
List<Tuple> res4 = jedis.zmove("scores:{example}", "moved:{example}", SortedSetOption.MAX);
System.out.println(res4); // >>> [[three,3.0]]
List<Tuple> res5 = jedis.zrangeWithScores("moved:{example}", 0, -1);
System.out.println(res5); // >>> [[one,1.0], [three,3.0], [retained,100.0]]
List<Tuple> res6 = jedis.zrangeWithScores("scores:{example}", 0, -1);
System.out.println(res6); // >>> [[two,2.0]]
long res7 = jedis.zadd("ready:{example}", new HashMap<String, Double>() {{
put("first", 1d);
put("second", 2d);
}});
System.out.println(res7); // >>> 2
List<Tuple> res8 = jedis.bzmove("ready:{example}", "processing:{example}", SortedSetOption.MIN, 1, 3);
System.out.println(res8); // >>> [[first,1.0], [second,2.0]]
long res9 = jedis.zadd("bookmarks:{user:42}", new HashMap<String, Double>() {{
put("bookmark:a", 1699999998d);
put("bookmark:b", 1699999999d);
put("bookmark:c", 1700000000d);
}});
System.out.println(res9); // >>> 3
List<Tuple> res10 = jedis.zmoveByScore("bookmarks:{user:42}", "batch:{user:42}:001", "-inf", "(1700000000", 500);
System.out.println(res10); // >>> [[bookmark:a,1.699999998E9], [bookmark:b,1.699999999E9]]
List<Tuple> res11 = jedis.zrangeWithScores("bookmarks:{user:42}", 0, -1);
System.out.println(res11); // >>> [[bookmark:c,1.7E9]]
List<Tuple> res12 = jedis.zmoveByScore("bookmarks:{user:42}", "batch:{user:42}:002", "-inf", "(1700000000", 500);
System.out.println(res12); // >>> null
long res13 = jedis.zadd("source:{example}", new HashMap<String, Double>() {{
put("one", 1d);
put("two", 2d);
}});
System.out.println(res13); // >>> 2
long res14 = jedis.zadd("destination:{example}", new HashMap<String, Double>() {{
put("two", 99d);
put("retained", 100d);
}});
System.out.println(res14); // >>> 2
List<Tuple> res15 = jedis.zmovemember("source:{example}", "destination:{example}", "missing", "two", "two");
System.out.println(res15); // >>> [[two,2.0]]
List<Tuple> res16 = jedis.zrangeWithScores("source:{example}", 0, -1);
System.out.println(res16); // >>> [[one,1.0]]
List<Tuple> res17 = jedis.zrangeWithScores("destination:{example}", 0, -1);
System.out.println(res17); // >>> [[two,2.0], [retained,100.0]]
long res18 = jedis.zadd("source:{conditional}", new HashMap<String, Double>() {{
put("existing", 1d);
put("new", 2d);
}});
System.out.println(res18); // >>> 2
long res19 = jedis.zadd("destination:{conditional}", new HashMap<String, Double>() {{
put("existing", 99d);
}});
System.out.println(res19); // >>> 1
List<Tuple> res20 = jedis.zmovemember("source:{conditional}", "destination:{conditional}",
ZMoveMemberParams.zMoveMemberParams().nx(), "existing", "new");
System.out.println(res20); // >>> [[new,2.0]]
Double res21 = jedis.zscore("source:{conditional}", "existing");
System.out.println(res21); // >>> 1.0
Tuple res22 = jedis.zmovemember("source:{conditional}", "destination:{conditional}",
ZMoveMemberParams.zMoveMemberParams().xx(), "existing");
System.out.println(res22); // >>> [existing,1.0]
List<Tuple> res23 = jedis.zrangeWithScores("destination:{conditional}", 0, -1);
System.out.println(res23); // >>> [[existing,1.0], [new,2.0]]
jedis.close();
}
}
res7, err := rdb.ZAdd(ctx, "ready:{example}",
redis.Z{Member: "first", Score: 1},
redis.Z{Member: "second", Score: 2},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res7) // >>> 2
res8, err := rdb.BZMoveCount(ctx,
"ready:{example}", "processing:{example}", "MIN", time.Second, 3,
).Result()
if err != nil {
panic(err)
}
fmt.Println(res8) // >>> [{1 first} {2 second}]
package example_commands_test
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
func ExampleClient_zmove() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
res1, err := rdb.ZAdd(ctx, "scores:{example}",
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(res1) // >>> 3
res2, err := rdb.ZAdd(ctx, "moved:{example}",
redis.Z{Member: "one", Score: 99},
redis.Z{Member: "retained", Score: 100},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res2) // >>> 2
res3, err := rdb.ZMove(ctx, "scores:{example}", "moved:{example}", "MIN").Result()
if err != nil {
panic(err)
}
fmt.Println(res3) // >>> [{1 one}]
res4, err := rdb.ZMove(ctx, "scores:{example}", "moved:{example}", "MAX").Result()
if err != nil {
panic(err)
}
fmt.Println(res4) // >>> [{3 three}]
res5, err := rdb.ZRangeWithScores(ctx, "moved:{example}", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(res5) // >>> [{1 one} {3 three} {100 retained}]
res6, err := rdb.ZRangeWithScores(ctx, "scores:{example}", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(res6) // >>> [{2 two}]
}
func ExampleClient_bzmove() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
res7, err := rdb.ZAdd(ctx, "ready:{example}",
redis.Z{Member: "first", Score: 1},
redis.Z{Member: "second", Score: 2},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res7) // >>> 2
res8, err := rdb.BZMoveCount(ctx,
"ready:{example}", "processing:{example}", "MIN", time.Second, 3,
).Result()
if err != nil {
panic(err)
}
fmt.Println(res8) // >>> [{1 first} {2 second}]
}
func ExampleClient_zmove_byscore() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
res9, err := rdb.ZAdd(ctx, "bookmarks:{user:42}",
redis.Z{Member: "bookmark:a", Score: 1699999998},
redis.Z{Member: "bookmark:b", Score: 1699999999},
redis.Z{Member: "bookmark:c", Score: 1700000000},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res9) // >>> 3
res10, err := rdb.ZMoveByScoreCount(ctx,
"bookmarks:{user:42}", "batch:{user:42}:001",
"-inf", "(1700000000", 500,
).Result()
if err != nil {
panic(err)
}
fmt.Println(res10) // >>> [{1.699999998e+09 bookmark:a} {1.699999999e+09 bookmark:b}]
res11, err := rdb.ZRangeWithScores(ctx, "bookmarks:{user:42}", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(res11) // >>> [{1.7e+09 bookmark:c}]
_, err = rdb.ZMoveByScoreCount(ctx,
"bookmarks:{user:42}", "batch:{user:42}:002",
"-inf", "(1700000000", 500,
).Result()
fmt.Println(err == redis.Nil) // >>> true
}
func ExampleClient_zmovemember() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
res13, err := rdb.ZAdd(ctx, "source:{example}",
redis.Z{Member: "one", Score: 1},
redis.Z{Member: "two", Score: 2},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res13) // >>> 2
res14, err := rdb.ZAdd(ctx, "destination:{example}",
redis.Z{Member: "two", Score: 99},
redis.Z{Member: "retained", Score: 100},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res14) // >>> 2
res15, err := rdb.ZMoveMember(ctx, "source:{example}", "destination:{example}",
"missing", "two", "two",
).Result()
if err != nil {
panic(err)
}
fmt.Println(res15) // >>> [{2 two}]
res16, err := rdb.ZRangeWithScores(ctx, "source:{example}", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(res16) // >>> [{1 one}]
res17, err := rdb.ZRangeWithScores(ctx, "destination:{example}", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(res17) // >>> [{2 two} {100 retained}]
}
func ExampleClient_zmovemember_cond() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
res18, err := rdb.ZAdd(ctx, "source:{conditional}",
redis.Z{Member: "existing", Score: 1},
redis.Z{Member: "new", Score: 2},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res18) // >>> 2
res19, err := rdb.ZAdd(ctx, "destination:{conditional}",
redis.Z{Member: "existing", Score: 99},
).Result()
if err != nil {
panic(err)
}
fmt.Println(res19) // >>> 1
res20, err := rdb.ZMoveMemberWithArgs(ctx,
"source:{conditional}", "destination:{conditional}",
redis.ZMoveMemberNX, "existing", "new",
).Result()
if err != nil {
panic(err)
}
fmt.Println(res20) // >>> [{2 new}]
res21, err := rdb.ZScore(ctx, "source:{conditional}", "existing").Result()
if err != nil {
panic(err)
}
fmt.Println(res21) // >>> 1
res22, err := rdb.ZMoveMemberWithArgs(ctx,
"source:{conditional}", "destination:{conditional}",
redis.ZMoveMemberXX, "existing",
).Result()
if err != nil {
panic(err)
}
fmt.Println(res22) // >>> [{1 existing}]
res23, err := rdb.ZRangeWithScores(ctx, "destination:{conditional}", 0, -1).Result()
if err != nil {
panic(err)
}
fmt.Println(res23) // >>> [{1 existing} {2 new}]
}
$res7 = $r->zadd('ready:{example}', ['first' => 1, 'second' => 2]);
echo $res7 . PHP_EOL;
// >>> 2
$res8 = $r->bzmove('ready:{example}', 'processing:{example}', 'MIN', 1, 3);
echo json_encode($res8) . PHP_EOL;
// >>> {"first":1,"second":2}
<?php
use Predis\Client as PredisClient;
class CmdsZmoveTest
{
public function testCmdsZmove() {
$r = new PredisClient([
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379,
'password' => '',
'database' => 0,
]);
$res1 = $r->zadd('scores:{example}', ['one' => 1, 'two' => 2, 'three' => 3]);
echo $res1 . PHP_EOL;
// >>> 3
$res2 = $r->zadd('moved:{example}', ['one' => 99, 'retained' => 100]);
echo $res2 . PHP_EOL;
// >>> 2
$res3 = $r->zmove('scores:{example}', 'moved:{example}', 'MIN');
echo json_encode($res3) . PHP_EOL;
// >>> {"one":1}
$res4 = $r->zmove('scores:{example}', 'moved:{example}', 'MAX');
echo json_encode($res4) . PHP_EOL;
// >>> {"three":3}
$res5 = $r->zrange('moved:{example}', 0, -1, ['withscores' => true]);
echo json_encode($res5) . PHP_EOL;
// >>> {"one":"1","three":"3","retained":"100"}
$res6 = $r->zrange('scores:{example}', 0, -1, ['withscores' => true]);
echo json_encode($res6) . PHP_EOL;
// >>> {"two":"2"}
$res7 = $r->zadd('ready:{example}', ['first' => 1, 'second' => 2]);
echo $res7 . PHP_EOL;
// >>> 2
$res8 = $r->bzmove('ready:{example}', 'processing:{example}', 'MIN', 1, 3);
echo json_encode($res8) . PHP_EOL;
// >>> {"first":1,"second":2}
$res9 = $r->zadd('bookmarks:{user:42}', [
'bookmark:a' => 1699999998,
'bookmark:b' => 1699999999,
'bookmark:c' => 1700000000,
]);
echo $res9 . PHP_EOL;
// >>> 3
$res10 = $r->zmove('bookmarks:{user:42}', 'batch:{user:42}:001', ['-inf', '(1700000000'], 500);
echo json_encode($res10) . PHP_EOL;
// >>> {"bookmark:a":1699999998,"bookmark:b":1699999999}
$res11 = $r->zrange('bookmarks:{user:42}', 0, -1, ['withscores' => true]);
echo json_encode($res11) . PHP_EOL;
// >>> {"bookmark:c":"1700000000"}
$res12 = $r->zmove('bookmarks:{user:42}', 'batch:{user:42}:002', ['-inf', '(1700000000'], 500);
echo json_encode($res12) . PHP_EOL;
// >>> null
$res13 = $r->zadd('source:{example}', ['one' => 1, 'two' => 2]);
echo $res13 . PHP_EOL;
// >>> 2
$res14 = $r->zadd('destination:{example}', ['two' => 99, 'retained' => 100]);
echo $res14 . PHP_EOL;
// >>> 2
$res15 = $r->zmovemember('source:{example}', 'destination:{example}', ['missing', 'two', 'two']);
echo json_encode($res15) . PHP_EOL;
// >>> {"two":2}
$res16 = $r->zrange('source:{example}', 0, -1, ['withscores' => true]);
echo json_encode($res16) . PHP_EOL;
// >>> {"one":"1"}
$res17 = $r->zrange('destination:{example}', 0, -1, ['withscores' => true]);
echo json_encode($res17) . PHP_EOL;
// >>> {"two":"2","retained":"100"}
$res18 = $r->zadd('source:{conditional}', ['existing' => 1, 'new' => 2]);
echo $res18 . PHP_EOL;
// >>> 2
$res19 = $r->zadd('destination:{conditional}', ['existing' => 99]);
echo $res19 . PHP_EOL;
// >>> 1
$res20 = $r->zmovemember('source:{conditional}', 'destination:{conditional}', ['existing', 'new'], 'NX');
echo json_encode($res20) . PHP_EOL;
// >>> {"new":2}
$res21 = $r->zscore('source:{conditional}', 'existing');
echo $res21 . PHP_EOL;
// >>> 1
$res22 = $r->zmovemember('source:{conditional}', 'destination:{conditional}', ['existing'], 'XX');
echo json_encode($res22) . PHP_EOL;
// >>> {"existing":1}
$res23 = $r->zrange('destination:{conditional}', 0, -1, ['withscores' => true]);
echo json_encode($res23) . PHP_EOL;
// >>> {"existing":"1","new":"2"}
}
}
To wait for a producer, run the following command when ready:{queue} does
not exist:
BZMOVE ready:{queue} processing:{queue} MIN 0 COUNT 10
In a second connection, run ZADD ready:{queue} 1 job:1. The blocked command
returns one nested member/score pair for job:1; it does not wait for nine
more members.
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
Return information
One of the following:
- Array reply: an array of two-element member/score arrays, nested even when only one member is moved. Each score is a bulk string. Pairs follow the selected order.
- Nil reply: the timeout expired, both keys name the same sorted set, or blocking is disallowed and no member is available.