-
Notifications
You must be signed in to change notification settings - Fork 456
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
Add new MPUBLISH command #1657
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,20 +27,48 @@ namespace redis { | |
|
||
class CommandPublish : public Commander { | ||
public: | ||
// mark is_write as false here because slave should be able to execute publish command | ||
Status Execute(Server *svr, Connection *conn, std::string *output) override { | ||
if (!svr->IsSlave()) { | ||
// Compromise: can't replicate message to sub-replicas in a cascading-like structure. | ||
// Replication relies on WAL seq, increase the seq on slave will break the replication, hence the compromise | ||
// Compromise: can't replicate a message to sub-replicas in a cascading-like structure. | ||
// Replication relies on WAL seq; increasing the seq on a replica will break the replication process, | ||
// hence the compromise solution | ||
redis::PubSub pubsub_db(svr->storage); | ||
|
||
auto s = pubsub_db.Publish(args_[1], args_[2]); | ||
if (!s.ok()) { | ||
return {Status::RedisExecErr, s.ToString()}; | ||
} | ||
} | ||
|
||
int receivers = svr->PublishMessage(args_[1], args_[2]); | ||
|
||
*output = redis::Integer(receivers); | ||
|
||
return Status::OK(); | ||
} | ||
}; | ||
|
||
class CommandMPublish : public Commander { | ||
public: | ||
Status Execute(Server *svr, Connection *conn, std::string *output) override { | ||
int total_receivers = 0; | ||
|
||
for (size_t i = 2; i < args_.size(); i++) { | ||
if (!svr->IsSlave()) { | ||
redis::PubSub pubsub_db(svr->storage); | ||
|
||
auto s = pubsub_db.Publish(args_[1], args_[i]); | ||
if (!s.ok()) { | ||
return {Status::RedisExecErr, s.ToString()}; | ||
} | ||
} | ||
|
||
int receivers = svr->PublishMessage(args_[1], args_[i]); | ||
total_receivers += receivers; | ||
} | ||
|
||
*output = redis::Integer(total_receivers); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would an array of int be better here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds ok. It's ok to leave it like this |
||
|
||
return Status::OK(); | ||
} | ||
}; | ||
|
@@ -132,7 +160,7 @@ class CommandPubSub : public Commander { | |
return Status::OK(); | ||
} | ||
|
||
return {Status::RedisInvalidCmd, "Unknown subcommand or wrong number of arguments"}; | ||
return {Status::RedisInvalidCmd, errUnknownSubcommandOrWrongArguments}; | ||
} | ||
|
||
Status Execute(Server *srv, Connection *conn, std::string *output) override { | ||
|
@@ -161,7 +189,7 @@ class CommandPubSub : public Commander { | |
return Status::OK(); | ||
} | ||
|
||
return {Status::RedisInvalidCmd, "Unknown subcommand or wrong number of arguments"}; | ||
return {Status::RedisInvalidCmd, errUnknownSubcommandOrWrongArguments}; | ||
} | ||
|
||
private: | ||
|
@@ -172,6 +200,7 @@ class CommandPubSub : public Commander { | |
|
||
REDIS_REGISTER_COMMANDS( | ||
MakeCmdAttr<CommandPublish>("publish", 3, "read-only pub-sub", 0, 0, 0), | ||
MakeCmdAttr<CommandMPublish>("mpublish", -3, "read-only pub-sub", 0, 0, 0), | ||
MakeCmdAttr<CommandSubscribe>("subscribe", -2, "read-only pub-sub no-multi no-script", 0, 0, 0), | ||
MakeCmdAttr<CommandUnSubscribe>("unsubscribe", -1, "read-only pub-sub no-multi no-script", 0, 0, 0), | ||
MakeCmdAttr<CommandPSubscribe>("psubscribe", -2, "read-only pub-sub no-multi no-script", 0, 0, 0), | ||
|
There was a problem hiding this comment.
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?