summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--redis.conf5
-rw-r--r--src/config.c11
-rw-r--r--src/server.c7
-rw-r--r--src/server.h2
4 files changed, 24 insertions, 1 deletions
diff --git a/redis.conf b/redis.conf
index 13b29c428..3bb52e76d 100644
--- a/redis.conf
+++ b/redis.conf
@@ -409,6 +409,11 @@ set-proc-title yes
#
proc-title-template "{title} {listen-addr} {server-mode}"
+# Set the local environment which is used for string comparison operations, and
+# also affect the performance of Lua scripts. Empty String indicates the locale
+# is derived from the environment variables.
+locale-collate ""
+
################################ SNAPSHOTTING ################################
# Save the DB to disk.
diff --git a/src/config.c b/src/config.c
index 0ffe65a61..f98225cbe 100644
--- a/src/config.c
+++ b/src/config.c
@@ -35,6 +35,7 @@
#include <sys/stat.h>
#include <glob.h>
#include <string.h>
+#include <locale.h>
/*-----------------------------------------------------------------------------
* Config file name-value maps.
@@ -2400,6 +2401,15 @@ static int isValidProcTitleTemplate(char *val, const char **err) {
return 1;
}
+static int updateLocaleCollate(const char **err) {
+ const char *s = setlocale(LC_COLLATE, server.locale_collate);
+ if (s == NULL) {
+ *err = "Invalid locale name";
+ return 0;
+ }
+ return 1;
+}
+
static int updateProcTitleTemplate(const char **err) {
if (redisSetProcTitle(NULL) == C_ERR) {
*err = "failed to set process title";
@@ -2995,6 +3005,7 @@ standardConfig static_configs[] = {
createStringConfig("proc-title-template", NULL, MODIFIABLE_CONFIG, ALLOW_EMPTY_STRING, server.proc_title_template, CONFIG_DEFAULT_PROC_TITLE_TEMPLATE, isValidProcTitleTemplate, updateProcTitleTemplate),
createStringConfig("bind-source-addr", NULL, MODIFIABLE_CONFIG, EMPTY_STRING_IS_NULL, server.bind_source_addr, NULL, NULL, NULL),
createStringConfig("logfile", NULL, IMMUTABLE_CONFIG, ALLOW_EMPTY_STRING, server.logfile, "", NULL, NULL),
+ createStringConfig("locale-collate", NULL, MODIFIABLE_CONFIG, ALLOW_EMPTY_STRING, server.locale_collate, "", NULL, updateLocaleCollate),
/* SDS Configs */
createSDSConfig("masterauth", NULL, MODIFIABLE_CONFIG | SENSITIVE_CONFIG, EMPTY_STRING_IS_NULL, server.masterauth, NULL, NULL, NULL),
diff --git a/src/server.c b/src/server.c
index 3456f06c9..b96d95b75 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2440,6 +2440,12 @@ void initServer(void) {
server.reply_buffer_resizing_enabled = 1;
resetReplicationBuffer();
+ /* Make sure the locale is set on startup based on the config file. */
+ if (setlocale(LC_COLLATE,server.locale_collate) == NULL) {
+ serverLog(LL_WARNING, "Failed to configure LOCALE for invalid locale name.");
+ exit(1);
+ }
+
if ((server.tls_port || server.tls_replication || server.tls_cluster)
&& tlsConfigure(&server.tls_ctx_config) == C_ERR) {
serverLog(LL_WARNING, "Failed to configure TLS. Check logs for more info.");
@@ -6910,7 +6916,6 @@ int main(int argc, char **argv) {
#ifdef INIT_SETPROCTITLE_REPLACEMENT
spt_init(argc, argv);
#endif
- setlocale(LC_COLLATE,"");
tzset(); /* Populates 'timezone' global. */
zmalloc_set_oom_handler(redisOutOfMemoryHandler);
diff --git a/src/server.h b/src/server.h
index 685768803..c0f68c73f 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1944,6 +1944,8 @@ struct redisServer {
is down, doesn't affect pubsub global. */
long reply_buffer_peak_reset_time; /* The amount of time (in milliseconds) to wait between reply buffer peak resets */
int reply_buffer_resizing_enabled; /* Is reply buffer resizing enabled (1 by default) */
+ /* Local environment */
+ char *locale_collate;
};
#define MAX_KEYS_BUFFER 256