Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new MPUBLISH command #1657

Merged
merged 2 commits into from
Aug 11, 2023
Merged

Add new MPUBLISH command #1657

merged 2 commits into from
Aug 11, 2023

Conversation

torwig
Copy link
Contributor

@torwig torwig commented Aug 9, 2023

The new MPUBLISH command allows publishing one or more messages to a channel.
Syntax: MPUBLISH channel-name message1 message2 ... messageN

Copy link
Member

@enjoy-binbin enjoy-binbin left a comment

Choose a reason for hiding this comment

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

I'll add some refs first.
redis have this pending issue: [QUESTION] Why not allow PUBLISH to publish multiple messages?
and this pending PR: How MPUBLISH could work #12267

@torwig
Copy link
Contributor Author

torwig commented Aug 9, 2023

@enjoy-binbin Thank you for the links.

@torwig
Copy link
Contributor Author

torwig commented Aug 9, 2023

I guess I should consider introducing a new command for this instead of changing the PUBLISH command.

@caipengbo
Copy link
Contributor

I guess I should consider introducing a new command for this instead of changing the PUBLISH command.

Agree with it

@enjoy-binbin
Copy link
Member

Do you already want to use this feature? One case is we can pipeline it in this monment (Waiting for Redis to actually implement it if not in a hurry).

or implementing MPUBLISH channel message1 message2 .... This should be possible since it should be implemented in Redis 8 (i see two Redis core-team member agree with it)

@aleksraiden
Copy link
Contributor

Thanks, @enjoy-binbin @torwig

Yes, variant MPUBLISH channel message1 message2 will be awesome

@torwig torwig changed the title Add ability to pass multiple messages to the PUBLISH command Add new MPUBLISH command Aug 10, 2023
@torwig
Copy link
Contributor Author

torwig commented Aug 10, 2023

Implemented the feature as a separate command MPUBLISH.

redis::PubSub pubsub_db(svr->storage);

auto s = pubsub_db.Publish(args_[1], args_[i]);
if (!s.ok()) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems that Publish will be likely to success?

total_receivers += receivers;
}

*output = redis::Integer(total_receivers);
Copy link
Member

Choose a reason for hiding this comment

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

Would an array of int be better here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mapleFU Possibly, yes. However, according to this PR (redis/redis#12267) it's likely that MPUBLISH will have a single integer as a response.

Copy link
Member

Choose a reason for hiding this comment

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

Oh this LGTM. Seems this is not stable. Maybe we can mark "mpublish" as "experimental" or something, and make it able to change the syntax of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general, I think it's not easy to utilize the return value of the PUBLISH command, except to check whether it is 0 or more. The actual goal of Pub/Sub pattern is to decouple publishers from subscribers and if I want to check the number of receivers I should know the exact number of them. And for example, if I know that there should be 5 subscribers but I received only 4 in response to the PUBLISH command, what should I do?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds ok. It's ok to leave it like this

Copy link
Contributor

@caipengbo caipengbo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

This patch general LGTM. I've some tiny problems.

Seems pubsub_db.Publish different messages separately. It's ok if all write works well. However, could user find how many message is successed when Publish failed?

Another is that this calls a look for each arg. Could we make mpublish faster, and batch the notifying later? Would this save some time?

Return
Integer reply: the number of clients that received the message.
Note that in a cluster, only clients that are connected to the same node
as the publishing client are included in the count.
@PragmaTwice PragmaTwice merged commit c9da1ea into apache:unstable Aug 11, 2023
26 checks passed
p1u3o pushed a commit to p1u3o/incubator-kvrocks that referenced this pull request Aug 15, 2023
The new `MPUBLISH` command allows publishing one or more messages to a channel. 
Syntax: `MPUBLISH channel-name message1 message2 ... messageN`
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.

7 participants