Skip to content

Conversation

@anarthal
Copy link
Collaborator

@anarthal anarthal commented Jan 7, 2026

No description provided.

@anarthal
Copy link
Collaborator Author

anarthal commented Jan 7, 2026

I've created this PR to discuss on how to proceed with type-safe command wrappers. These are needed for:

  1. PubSub state restoration (Pubsub state restoration #367), for the SUBSCRIBE, PSUBSCRIBE, UNSUBCRIBE and PUNSUBSCRIBE commands. We need to inspect all the channels the user is manipulating, so we know how to resubscribe on reconnection.
  2. Cluster (Cluster feature with Boost.Redis #374), for all commands that act on a key. We need to compute the key's hash so we know which node we should send each command to.

I'm concerned about the size that this would add to request, specially for point 2, since most commands act on a key. I've generated the current prototype with AI just to get a feel of the size this would have.

I see several options here:

  1. Go with this approach. I'd open another PR supporting only the ones required for PubSub, properly implemented and tested.
  2. Go with this approach for PubSub state restoration, but think of something else for cluster. For example:
req.push_get("mykey"); // GET is common, so we have a command for it that computes the key's hash
req.push_routed(hash_of("mykey"), "GEOADD", "mykey", 1.35, 2.05, "Palermo"); // GEOADD is not common, so the user needs to provide how to hash the command manually
  1. Think of something more modular. The best I've been able to come up with is:
req.push_cmd(cmds::get, "mykey");
req.push_cmd(cmds::subscribe, std::array{"chan1", "chan2"}); // doesn't work without the explicit std::array because push_cmd forwards arguments

or

req.cmd(cmds::get).args("mykey");
req.cmd(cmds::subscribe).args({"chan1", "chan2"}); // supports initializer lists

@mzimbres what's your view on this?

@anarthal
Copy link
Collaborator Author

anarthal commented Jan 9, 2026

Closing this as it was a prototype for discussion, and the direction has been set to explicit functions like request::subscribe.

@anarthal anarthal closed this Jan 9, 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.

1 participant