diff --git a/src/cluster.c b/src/cluster.c index 9154ac3207..7eedff6864 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -1471,12 +1471,24 @@ void askingCommand(client *c) { * In this mode replica will not redirect clients as long as clients access * with read-only commands to keys that are served by the replica's primary. */ void readonlyCommand(client *c) { + if (server.cluster_enabled == 0 && !(c->capa & CLIENT_CAPA_REDIRECT)) { + addReplyError(c, "This instance has cluster support disabled," + " you need to execute the CLIENT CAPA REDIRECT command," + " before you can use the READONLY command in standalone mode."); + return; + } c->flag.readonly = 1; addReply(c, shared.ok); } /* The READWRITE command just clears the READONLY command state. */ void readwriteCommand(client *c) { + if (server.cluster_enabled == 0 && !(c->capa & CLIENT_CAPA_REDIRECT)) { + addReplyError(c, "This instance has cluster support disabled," + " you need to execute the CLIENT CAPA REDIRECT command," + " before you can use the READWRITE command in standalone mode."); + return; + } c->flag.readonly = 0; addReply(c, shared.ok); } diff --git a/tests/integration/replica-redirect.tcl b/tests/integration/replica-redirect.tcl index b4e5a74b66..a1582aa628 100644 --- a/tests/integration/replica-redirect.tcl +++ b/tests/integration/replica-redirect.tcl @@ -9,6 +9,11 @@ start_server {tags {needs:repl external:skip}} { set replica_port [srv 0 port] set replica_pid [srv 0 pid] + test {READONLY and READWRITE commands are disabled by default} { + assert_error {*cluster*disabled*READONLY*standalone*} {r readonly} + assert_error {*cluster*disabled*READWRITE*standalone*} {r readwrite} + } + test {write command inside MULTI is QUEUED, EXEC should be REDIRECT} { set rr [valkey_client] $rr client capa redirect