Skip to content

Add bzmove,zmove,zmovemember commands - #10430

Closed
vikeychen wants to merge 1 commit into
redis:unstablefrom
vikeychen:zmove-commands
Closed

vikeychen wants to merge 1 commit into
redis:unstablefrom
vikeychen:zmove-commands

Conversation

@vikeychen

@vikeychen vikeychen commented Mar 15, 2022 •

Copy link
Copy Markdown
Contributor

zmove is like lmove,the format is ZMOVE <source> <destination> MIN|MAX, when specify min the moved element will be the minimum score element in the source.

bzmove is the blocking version of zmove.

zmovmember is like smove, the format is ZMOVEMEMBER <source> <destination> member.

see #9989


Note

Medium Risk
Adds new write and blocking sorted-set commands that modify keyspace events, replication rewriting, and memory/keysize accounting paths; mistakes could cause inconsistent state or replication divergence.

Overview
Adds three new sorted-set commands: ZMOVE (move min/max element), ZMOVEMEMBER (move a specific member), and blocking BZMOVE (wait for an element, then move it).

Implements shared move logic in t_zset.c, including helpers to fetch min/max elements across encodings, proper deletion/creation of source/destination keys, keyspace notifications, dirty/memory/keysize accounting, and replication rewriting (BZMOVE propagates as ZMOVE).

Updates command metadata (commands.def and new src/commands/*.json), registers new shared object/prototypes, and adds extensive integration/unit tests for clustering (CROSSSLOT), COMMAND introspection, replication behavior, blocking semantics, RESP parsing, and wrong-type/syntax handling.

Reviewed by Cursor Bugbot for commit 1733a7c. Bugbot is set up for automated code reviews on this repo. Configure here.

@oranagra

Copy link
Copy Markdown
Member

Thanks @vikeychen .
this is now too late to fit this into Redis 7.0, which is currently in focus to get released.
it'll have to wait a while before we can look into it for 7.2

@vikeychen

Copy link
Copy Markdown
Contributor Author

@oranagra got it, I will wait...

@VeaaC

VeaaC commented Jan 17, 2023

Copy link
Copy Markdown

Is this still in scope for 7.2?

@oranagra oranagra linked an issue Jan 18, 2023 that may be closed by this pull request
@jamesw6811

Copy link
Copy Markdown

I'm also excited for this.

@heaven

heaven commented May 25, 2023

Copy link
Copy Markdown

@oranagra any chance to have this merged?

@oranagra

Copy link
Copy Markdown
Member

sorry about the late response. 7.2 is mainly focused on optimizations, we'll consider this for 8.0

@CLAassistant

CLAassistant commented Mar 24, 2024 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sundb sundb removed this from Redis 8.2 Aug 19, 2025
@piskvorky

piskvorky commented Apr 24, 2026 •

Copy link
Copy Markdown

@sundb @oranagra What's the status on this PR? This is really cool functionality.

@sundb sundb removed this from Redis Backlog Apr 24, 2026
@sundb sundb added this to Redis 8.8 Apr 24, 2026
@sundb

sundb commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

@vikeychen are you still around? pls fix the conflicts. thx

@vikeychen

Copy link
Copy Markdown
Contributor Author

@vikeychen are you still around? pls fix the conflicts. thx

I’ve already fixed the conflicts and pushed the update. Happy to make any further changes if needed.

@sundb sundb added this to Redis 8.10 May 21, 2026
@sundb sundb removed this from Redis 8.8 May 21, 2026
@sundb sundb removed this from Redis 8.10 Aug 4, 2026
@sundb sundb added this to Redis 8.12 Aug 4, 2026
@fcenedes

Copy link
Copy Markdown
Contributor

Hey @vikeychen

more conflicts ;-) Would love to see this pr merged.
is there anything i could help with?

@piskvorky

piskvorky commented Oct 30, 2026 •

Copy link
Copy Markdown

I think the core devs are waiting for a 5-year anniversary of this PR to merge 🥳

sundb added a commit that referenced this pull request Nov 11, 2026
…16135)

Adds atomic sorted-set moves for end-of-set batches, score ranges and
named members. Continues #10430 by @vikeychen. Related: #9989. Docs:
redis/docs#4522.

```text
ZMOVE        source destination <MIN | MAX | BYSCORE score-min score-max> [COUNT count]
BZMOVE       source destination <MIN | MAX> timeout [COUNT count]
ZMOVEMEMBER  source destination [NX | XX] MEMBERS num-members member [member ...]
```

### Reply

- When members are moved, the reply is an array of `[member, score]`
pairs, nested even for one member. Scores are bulk strings in RESP2 and
doubles in RESP3.
- When nothing is moved, the reply is nil (RESP2 `*-1`, RESP3 `_`). That
covers a missing source, no matching or eligible member, source ==
destination, and a BZMOVE timeout. It also covers BZMOVE inside MULTI or
a script when the source is empty.
- Reply order:
  - MIN and BYSCORE: ascending (score, then member);
  - MAX: descending;
- ZMOVEMEMBER: argument order, with duplicates once and missing members
skipped.

### Semantics

- `COUNT` must be positive. Zero, negative or malformed values return
`ERR count should be greater than 0` before anything moves or blocks, as
ZMPOP does. The default count is 1 for MIN/MAX. BYSCORE moves the whole
matching range by default.
- `BYSCORE` takes ZRANGEBYSCORE-style bounds (`(`, `-inf`, `+inf`). It
has no LIMIT offset.
- `BZMOVE` blocks on the source only. It wakes as soon as the source has
a member and moves up to COUNT; it doesn't wait for a full batch. When
members are moved, it is propagated as `ZMOVE source destination MIN|MAX
[COUNT count]`.
- `ZMOVEMEMBER`:
- The counted `MEMBERS` block keeps member data apart from options, like
HSETEX `FIELDS`. NX/XX may appear before or after the block, so a member
named `NX` or `MEMBERS` is unambiguous.
- With NX, only members absent from the destination move; with XX, only
members already present there move. Members that aren't moved stay in
the source.
- With no condition, the source score overwrites the destination score.
- Source == destination returns nil right after the type check, without
reading any member. BZMOVE does not block in that case.
- An emptied source is deleted. An existing destination keeps its TTL; a
new destination has none. In cluster mode both keys must hash to the
same slot.

### Keyspace notifications

These fire only when at least one member moved:

- Source:
  - `zpopmin` / `zpopmax` for MIN/MAX;
  - `zrem` for BYSCORE and ZMOVEMEMBER;
  - `del` when the source is emptied.
- Destination: `zadd`, but only if the destination actually changed.
Moving a member that already has the same score doesn't count as a
change. A newly created destination also gets `new`.

---------

Co-authored-by: vikeychen <[email protected]>
Co-authored-by: debing.sun <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@sundb

sundb commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Closed via #16135
@vikeychen still thx for your effort.

@sundb sundb closed this Nov 11, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in Redis 8.12 Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[NEW] Blocking SMOVE/ZMOVE

9 participants