Skip to content

MOD-21460: Add JSON.COPY for single-location JSON paths - #1731

Open
TalBarYakar wants to merge 6 commits into
masterfrom
tal.ba/feat/json_copy_command
Open

TalBarYakar wants to merge 6 commits into
masterfrom
tal.ba/feat/json_copy_command

Conversation

@TalBarYakar

@TalBarYakar TalBarYakar commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Adds JSON.COPY to copy a stored JSON value within one document or between keys:

JSON.COPY source_key source_path destination_key destination_path [NX | XX]

Both paths must identify a single explicit location. The copied value replaces
the destination rather than merging with it. NX writes only to a missing
destination; XX writes only to an existing destination. Missing source keys
or paths return errors.

The source value is cloned before writing, so overlapping paths within the
same document use the original source value. Existing destination TTLs are
preserved; newly created keys have no TTL. Destination creation follows
JSON.SET rules, including json-auto-create-deep-paths.

The command uses the existing write and replication mechanisms and emits a
json.copy keyspace event. Key specifications enforce source read permission,
destination write permission, and same-slot routing in Cluster.

Includes command metadata with since: 99.99.99, a commands.json entry,
user documentation, and command-docs tests.

Validation

  • 45 flow tests passed, covering JSON.COPY behavior, metadata, ACLs,
    replication, and AOF replay/rewrite.
  • Two Cluster tests passed separately on a three-shard cluster, covering
    same-slot copies and server-side CROSSSLOT rejection.
  • Rust tests passed: 121 with default features and 122 with as-library,
    plus the documentation test in each configuration.
  • Diff whitespace checks passed.

Integration requirements and existing limitations

  • Search must add json.copy to its recognized notification events.
    Until that support is available, copying into an indexed document can
    leave its search index stale. Search changes are handled separately
    by the Search team.
  • json-auto-create-deep-paths must match between primary and replicas.
    JSON.COPY replicates verbatim, so different settings can produce different
    results when intermediate paths are missing. JSON.SET has the same limitation.
  • Packed numeric-array assignment retains the existing JSON.SET behavior,
    including its failure-handling limitations. This change does not add
    rollback guarantees for that shared path.
  • WATCH invalidation retains the existing writable-key behavior, including
    no-op cases. No dedicated WATCH regression tests were added.
  • Multi-location paths are not supported.

The full project test suite, load tests, and Search integration tests were
not run as part of this validation.


Note

Medium Risk
New write command touches key handling, persistence/replication, and ACL key specs; behavior reuses JSON.SET paths but adds cross-key mutation edge cases (overlap, depth, cluster slots).

Overview
Adds JSON.COPY, a write command that copies one JSON value from a static source path to a static destination path (same key or different keys), with optional NX / XX and the same destination-creation behavior as JSON.SET. Paths must resolve to a single location (wildcards, filters, and projections are rejected); the source is cloned before writing so overlapping paths keep the pre-copy value. The command registers with separate read/write key specs, emits json.copy keyspace events, and is wired through commands.json, user docs, and module registration.

Coverage includes ACL/key-permission and Cluster same-slot rules, replication and AOF replay/rewrite, command metadata tests, and a small CI fix that **chmod**s root-owned test logs dirs on failure so artifacts upload.

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

Replace the temporary json.set event with json.copy. Verify that successful copies notify only the destination once, while skipped and failed copies emit no event.

Search recognition of json.copy is a separate follow-up; older Search versions will not reindex from this event.
Cover cross-key copies, overlapping paths, NX/XX, expiration deadlines and source deletion. Verify replica state after each step and AOF recovery before and after rewrite, including that only successful writes enter the incremental stream.

Add JSON.COPY to the existing per-write-command replication coverage table.
Verify same-slot copies and server-side CROSSSLOT rejection across both same-node and different-node slots. Check independent source-read and destination-write grants, same-key permissions, and command-level denial without mutating data.

Include JSON.COPY in the JSON and write ACL category tests.
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.23077% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.34%. Comparing base (7ecc513) to head (00ed81a).

Files with missing lines Patch % Lines
redis_json/src/commands.rs 93.47% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1731      +/-   ##
==========================================
+ Coverage   88.24%   88.34%   +0.10%     
==========================================
  Files          18       18              
  Lines        6871     6975     +104     
==========================================
+ Hits         6063     6162      +99     
- Misses        808      813       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant