fix(client): COPY with DB 0 must emit the DB argument#3318
Merged
Conversation
nkaradzhov
approved these changes
Jul 2, 2026
nkaradzhov
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @spokodev, this looks good!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
COPY source destination { DB: 0 }silently drops theDB 0argument, so the key iscopied to the current database instead of database 0.
The destination-db guard in
packages/client/lib/commands/COPY.tsused a truthy check:0is a valid database index (the default database), but it is JS-falsy, so theDB 0tokens were never sent. A client connected to a non-zero database that asks to copy a key
into database 0 ends up writing the copy into its current database, with no error. Per the
COPY spec, the syntax is
COPY source destination [DB destination-db] [REPLACE]anddestination-dbcan be 0.The fix switches to an explicit
!== undefinedcheck, matching how every other numericcommand option in the client is guarded (BITPOS, XCLAIM, RESTORE, SCAN, and others). Added
a spec case covering
DB: 0; the existing suite only exercisedDB: 1.Checklist
npm testpass with this change (including linting)?Note
Low Risk
Single-line guard change in Redis command argument parsing plus a unit test; no auth, persistence, or API surface changes beyond correct COPY behavior for database 0.
Overview
Fixes
COPYso{ DB: 0 }is serialized asDB 0instead of being omitted.The destination-database guard in
COPY.tsused a truthy check onoptions?.DB, so index 0 (a valid Redis DB) never reached the wire and copies landed in the client’s current database. It now usesoptions?.DB !== undefined, consistent with other numeric options in the client.Adds a transform test for
DB: 0alongside the existingDB: 1case.Reviewed by Cursor Bugbot for commit cd95d7d. Bugbot is set up for automated code reviews on this repo. Configure here.