Skip to content

feat(redis): add a generic Do method to support arbitrary Redis commands (e.g., JSON.*) #5417

@1426919587

Description

@1426919587

Is your feature request related to a problem? Please describe.
The current Redis client in go-zero (core/stores/redis) only provides a fixed set of predefined methods (e.g., Set, Get, HSet). This becomes a serious limitation when using newer Redis features that introduce new commands — such as RedisJSON (JSON.SET, JSON.GET, etc.), which has been available since Redis 6.0 (via RedisJSON module) and is now built-in since Redis 7.2.
Because there's no way to execute arbitrary Redis commands, users cannot leverage these new capabilities directly. The only workaround is to use Lua scripts or integrate a third-party Redis client (like go-redis), which adds complexity, reduces performance, and breaks consistency with go-zero’s built-in Redis abstraction.

Describe the solution you'd like
Add a generic Do(ctx context.Context, ...) method to the redis.Redis struct (similar to go-redis), allowing users to execute any Redis command without waiting for go-zero to explicitly implement it.

Describe alternatives you've considered

  1. Using Lua scripts: We can embed JSON operations in Lua, but this is inefficient, hard to debug, and doesn’t scale well for complex queries.
  2. Wrapping another Redis client: We could use go-redis alongside go-zero’s client, but this leads to duplicated connections, inconsistent configuration, and loss of go-zero’s built-in features (e.g., metrics, tracing).
  3. Waiting for go-zero to add explicit JSON support: This is slow and doesn’t solve the root problem — every new Redis command would require a framework update.
    A generic Do method is the most flexible and sustainable solution.

Additional context

  • Redis 7.2+ has built-in JSON support, making JSON.* commands first-class citizens.
  • Many modern applications rely on Redis JSON for structured data storage (e.g., game rooms, user profiles).
  • Other popular Go Redis clients (like go-redis) already provide this flexibility via Do() or Process().
    Adding this small but powerful method would significantly improve go-zero’s compatibility with evolving Redis ecosystems while keeping the core simple.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions