diff --git a/src/config.c b/src/config.c index e40c24b5d8f..8b5c84ea899 100644 --- a/src/config.c +++ b/src/config.c @@ -1272,29 +1272,29 @@ int rewriteConfigRewriteLine(struct rewriteConfigState *state, const char *optio return 1; } -/* Write the long long 'bytes' value as a string in a way that is parsable +/* Write the unsigned long long 'bytes' value as a string in a way that is parsable * inside valkey.conf. If possible uses the GB, MB, KB notation. */ -int rewriteConfigFormatMemory(char *buf, size_t len, long long bytes) { +int rewriteConfigFormatMemory(char *buf, size_t len, unsigned long long bytes) { int gb = 1024 * 1024 * 1024; int mb = 1024 * 1024; int kb = 1024; if (bytes && (bytes % gb) == 0) { - return snprintf(buf, len, "%lldgb", bytes / gb); + return snprintf(buf, len, "%llugb", bytes / gb); } else if (bytes && (bytes % mb) == 0) { - return snprintf(buf, len, "%lldmb", bytes / mb); + return snprintf(buf, len, "%llumb", bytes / mb); } else if (bytes && (bytes % kb) == 0) { - return snprintf(buf, len, "%lldkb", bytes / kb); + return snprintf(buf, len, "%llukb", bytes / kb); } else { - return snprintf(buf, len, "%lld", bytes); + return snprintf(buf, len, "%llu", bytes); } } /* Rewrite a simple "option-name " configuration option. */ void rewriteConfigBytesOption(struct rewriteConfigState *state, const char *option, - long long value, - long long defvalue) { + unsigned long long value, + unsigned long long defvalue) { char buf[64]; int force = value != defvalue; sds line; diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl index 8fd5006a91c..c788abac0ba 100644 --- a/tests/unit/introspection.tcl +++ b/tests/unit/introspection.tcl @@ -1964,6 +1964,19 @@ test {CONFIG REWRITE handles alias config properly} { } } {} {external:skip} +test {CONFIG REWRITE handles large unsigned memory config values} { + start_server {tags {"introspection"}} { + r config set maxmemory 9223372036854775808 + r config set maxmemory-clients 100% + + r config rewrite + restart_server 0 true false + + assert_equal [lindex [r config get maxmemory] 1] 9223372036854775808 + assert_equal [lindex [r config get maxmemory-clients] 1] 100% + } +} {} {external:skip} + test {SIGNED MEMORY CONFIG allows negative number} { start_server {tags {"introspection"}} { r config set slot-migration-max-failover-repl-bytes -1