Repository navigation
Conversation
| "math", | ||
| "table", | ||
| "struct", | ||
| "os", |
There was a problem hiding this comment.
import os library would be dangerous, e.x os.execute, os.rename
Pardon my misunderstanding (on small screen phone), but maybe we shouldn't call it os.
There was a problem hiding this comment.
Yup, it could be replaced with "ros" or something else. The initial intention to name it 'os' is to conform to the concept of daily use.
| return lua_error(L); | ||
| } | ||
| const char *l = luaL_optstring(L, 1, NULL); | ||
| lua_pushstring(L, setlocale(LC_COLLATE, l)); |
There was a problem hiding this comment.
There was a problem hiding this comment.
CONFIG is indeed better cuz the environment is shared. I'll make changes in later commits.
There was a problem hiding this comment.
I think controlling locale through environment is more standard, having a configuration parameter that overrides that might be very counter intuitive in some cases. If a Lua script can change the locale programmatically, and that change only affects that script - I think that's much better.
There was a problem hiding this comment.
i'm not sure it's at all possible to have it only affect Lua.
indeed it's standard to control the locale via env var, but that's actually not very convenient.
i think that (despite being non-standard), it's much more useful to set such things via config file and config command).
same as we handle other global server configs like rdbcompression and ziplist threshold.
although granted, these do not affect behavior, just optimizations.
There was a problem hiding this comment.
Since it seems necessary to uniform the output format of SORT command globally (eg. the same business deployed in different regions), it may be better to control it from the upper level, i.e. CONFIG command.
There was a problem hiding this comment.
The title of this pr is easily misunderstood and I've created a new pr #11059
|
closing in favor of #11059 (to be controlled by a config, since we can't make sure it only affects Lua) |
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 <[email protected]> Co-authored-by: Oran Agra <[email protected]>
Till now Redis officially supported tuning it via environment variable see redis#1074. But we had other requests to allow changing it at runtime, see redis#799, and redis#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 <[email protected]> Co-authored-by: Oran Agra <[email protected]>
It is noted that Lua basically uses strcoll() as comparison function, which leads to a problem that, in different regions, for some characters, the comparison result may be different. Below is an example.

This will cause accidental code compatibility issues for Lua scripts. And here provides a solution.
This commit allows the use of setlocale() function of Lua os library. To avoid hidden systematic risk, the parameter category is set to collate and is unchangeable. The packaged function accepts only one parameter and the other functions of os library are unreachable. Allow setting locale offers an opportunity to uniform standards. Below shows how it works.