Skip to content

Comments

feat: Feature/json dump proper#3368

Open
Zakir032002 wants to merge 1 commit intoapache:unstablefrom
Zakir032002:feature/json-dump-proper
Open

feat: Feature/json dump proper#3368
Zakir032002 wants to merge 1 commit intoapache:unstablefrom
Zakir032002:feature/json-dump-proper

Conversation

@Zakir032002
Copy link
Contributor

@Zakir032002 Zakir032002 commented Feb 9, 2026

Summary

Add Redis-compatible DUMP/RESTORE support for JSON type using type coercion approach.

Maps JSON objects to Redis String type (RDBTypeString) during serialization, preserving data while maintaining full Redis compatibility. Similar to how SortedInt coerces to Set.

Closes #3319

Changes

Implementation Approach

  • SaveObjectType(): Maps kRedisJsonRDBTypeString
  • SaveObject(): Retrieves JSON via json_db.Get(), dumps to string, saves via SaveStringObject()
  • No custom RDB type: Uses standard Redis String encoding for full compatibility

Trade-offs

  • Redis Compatible: Any Redis instance can RESTORE the payload
  • Simple Implementation: Reuses existing String serialization
  • Data Preserved: JSON content fully preserved as string
  • ⚠️ Type Changes: After RESTORE, type becomes string (not ReJSON-RL)
  • ⚠️ Requires Re-import: Need JSON.SET to restore JSON functionality

This matches the pattern used for SortedInt (which becomes Set after RESTORE).

Testing

Manual Testing

127.0.0.1:6666> JSON.SET mykey $ '{"name":"Alice","age":30}'
OK

127.0.0.1:6666> TYPE mykey
ReJSON-RL

127.0.0.1:6666> DUMP mykey
"\x00\x19{\"age\":30,\"name\":\"Alice\"}\x06\x00 \xe8\x8f\xe8\xa4\x1a\xa5N"

127.0.0.1:6666> RESTORE newkey 0 "\x00\x19{\"age\":30,\"name\":\"Alice\"}\x06\x00 \xe8\x8f\xe8\xa4\x1a\xa5N"
OK

127.0.0.1:6666> TYPE newkey
string  # Type coerced to string

127.0.0.1:6666> GET newkey
"{\"age\":30,\"name\":\"Alice\"}"  # Data preserved

Copy link
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format design in this PR is not compatible with Redis at all. Not even close. Please ensure that you understand the design and the code.

@Zakir032002
Copy link
Contributor Author

Zakir032002 commented Feb 9, 2026

@PragmaTwice , Thank you for pointing this out, I will take this as learning and will do a proper implementation

- Map JSON type to RDBTypeString (type 0) for Redis compatibility
- Serialize JSON to string representation during DUMP
- RESTORE creates String type (similar to SortedInt → Set pattern)
- Add TestDump_JSON following existing test patterns
- Type changes: ReJSON-RL → string after RESTORE (trade-off for compatibility)
@Zakir032002 Zakir032002 force-pushed the feature/json-dump-proper branch from 08d5635 to 2e027c0 Compare February 11, 2026 07:22
@Zakir032002
Copy link
Contributor Author

From next time for these types can i just combine 2-3 type in a pr?

@Zakir032002 Zakir032002 changed the title feat : Feature/json dump proper feat: Feature/json dump proper Feb 11, 2026
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.

Add support of the DUMP with all data types

2 participants