diff --git a/src/cluster_legacy.c b/src/cluster_legacy.c index 63364d359..22fdb20cf 100644 --- a/src/cluster_legacy.c +++ b/src/cluster_legacy.c @@ -752,7 +752,6 @@ void clusterSaveConfigOrDie(int do_fsync) { serverLog(LL_WARNING, "Fatal: can't update cluster config file."); exit(1); } - clearCachedClusterSlotsResponse(); } /* Lock the cluster config using flock(), and retain the file descriptor used to @@ -4847,6 +4846,9 @@ void clusterBeforeSleep(void) { } void clusterDoBeforeSleep(int flags) { + /* Clear the cache if there are config changes here. */ + if (flags & CLUSTER_TODO_SAVE_CONFIG) clearCachedClusterSlotsResponse(); + server.cluster->todo_before_sleep |= flags; } diff --git a/tests/unit/cluster/hostnames.tcl b/tests/unit/cluster/hostnames.tcl index 7be4b42aa..98a6385c6 100644 --- a/tests/unit/cluster/hostnames.tcl +++ b/tests/unit/cluster/hostnames.tcl @@ -73,6 +73,20 @@ test "Verify cluster-preferred-endpoint-type behavior for redirects and info" { # Verify prefer hostname behavior R 0 config set cluster-preferred-endpoint-type hostname + # Make sure the cache is cleared when updating hostname. + R 0 multi + R 0 cluster slots + R 0 config set cluster-announce-hostname "new-me.com" + R 0 cluster slots + set multi_result [R 0 exec] + set slot_result1 [lindex $multi_result 0] + set slot_result2 [lindex $multi_result 2] + assert_equal "me.com" [get_slot_field $slot_result1 0 2 0] + assert_equal "new-me.com" [get_slot_field $slot_result2 0 2 0] + + # Set it back to its original value. + R 0 config set cluster-announce-hostname "me.com" + set slot_result [R 0 cluster slots] assert_equal "me.com" [get_slot_field $slot_result 0 2 0] assert_equal "them.com" [get_slot_field $slot_result 2 2 0]