From ca6aeadfbef8a0da8817f9f74a7bde1f5df004f7 Mon Sep 17 00:00:00 2001 From: yourtree <56780191+yourtree@users.noreply.github.com> Date: Sun, 21 Aug 2022 22:55:45 +0800 Subject: Support setlocale via CONFIG operation. (#11059) Till now Redis officially supported tuning it via environment variable see #1074. But we had other requests to allow changing it at runtime, see #799, and #11041. Note that `strcoll()` is used as Lua comparison function and also for comparison of certain string objects in Redis, which leads to a problem that, in different regions, for some characters, the result may be different. Below is an example. ``` 127.0.0.1:6333> SORT test alpha 1) "<" 2) ">" 3) "," 4) "*" 127.0.0.1:6333> CONFIG GET locale-collate 1) "locale-collate" 2) "" 127.0.0.1:6333> CONFIG SET locale-collate 1 (error) ERR CONFIG SET failed (possibly related to argument 'locale') 127.0.0.1:6333> CONFIG SET locale-collate C OK 127.0.0.1:6333> SORT test alpha 1) "*" 2) "," 3) "<" 4) ">" ``` That will cause accidental code compatibility issues for Lua scripts and some Redis commands. This commit creates a new config parameter to control the local environment which only affects `Collate` category. Above shows how it affects `SORT` command, and below shows the influence on Lua scripts. ``` 127.0.0.1:6333> CONFIG GET locale-collate 1) " locale-collate" 2) "C" 127.0.0.1:6333> EVAL "return ',' < '*'" 0 (nil) 127.0.0.1:6333> CONFIG SET locale-collate "" OK 127.0.0.1:6333> EVAL "return ',' < '*'" 0 (integer) 1 ``` Co-authored-by: calvincjli Co-authored-by: Oran Agra --- redis.conf | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'redis.conf') 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. -- cgit v1.2.1