summaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorMeir Shpilraien (Spielrein) <meir@redis.com>2022-04-05 10:27:24 +0300
committerGitHub <noreply@github.com>2022-04-05 10:27:24 +0300
commitae020e3d5665e46dbd2704b46b6ad207dd4471d9 (patch)
tree607ca81a18206b91131b94f34d25c596d30f3a88 /tests/integration
parent2db0d898f8d9daef34a6b9678a905a51cc43c298 (diff)
downloadredis-ae020e3d5665e46dbd2704b46b6ad207dd4471d9.tar.gz
Functions: Move library meta data to be part of the library payload. (#10500)
## Move library meta data to be part of the library payload. Following the discussion on https://github.com/redis/redis/issues/10429 and the intention to add (in the future) library versioning support, we believe that the entire library metadata (like name and engine) should be part of the library payload and not provided by the `FUNCTION LOAD` command. The reasoning behind this is that the programmer who developed the library should be the one who set those values (name, engine, and in the future also version). **It is not the responsibility of the admin who load the library into the database.** The PR moves all the library metadata (engine and function name) to be part of the library payload. The metadata needs to be provided on the first line of the payload using the shebang format (`#!<engine> name=<name>`), example: ```lua #!lua name=test redis.register_function('foo', function() return 1 end) ``` The above script will run on the Lua engine and will create a library called `test`. ## API Changes (compare to 7.0 rc2) * `FUNCTION LOAD` command was change and now it simply gets the library payload and extract the engine and name from the payload. In addition, the command will now return the function name which can later be used on `FUNCTION DELETE` and `FUNCTION LIST`. * The description field was completely removed from`FUNCTION LOAD`, and `FUNCTION LIST` ## Breaking Changes (compare to 7.0 rc2) * Library description was removed (we can re-add it in the future either as part of the shebang line or an additional line). * Loading an AOF file that was generated by either 7.0 rc1 or 7.0 rc2 will fail because the old command syntax is invalid. ## Notes * Loading an RDB file that was generated by rc1 / rc2 **is** supported, Redis will automatically add the shebang to the libraries payloads (we can probably delete that code after 7.0.3 or so since there's no need to keep supporting upgrades from an RC build).
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/redis-cli.tcl6
-rw-r--r--tests/integration/replication-4.tcl2
-rw-r--r--tests/integration/replication.tcl12
3 files changed, 13 insertions, 7 deletions
diff --git a/tests/integration/redis-cli.tcl b/tests/integration/redis-cli.tcl
index 7479ac8b4..e159fb17d 100644
--- a/tests/integration/redis-cli.tcl
+++ b/tests/integration/redis-cli.tcl
@@ -346,7 +346,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
set dir [lindex [r config get dir] 1]
assert_equal "OK" [r debug populate 100000 key 1000]
- assert_equal "OK" [r function load lua lib1 "redis.register_function('func1', function() return 123 end)"]
+ assert_equal "lib1" [r function load "#!lua name=lib1\nredis.register_function('func1', function() return 123 end)"]
if {$functions_only} {
set args "--functions-rdb $dir/cli.rdb"
} else {
@@ -359,10 +359,10 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS
file rename "$dir/cli.rdb" "$dir/dump.rdb"
assert_equal "OK" [r set should-not-exist 1]
- assert_equal "OK" [r function load lua should_not_exist_func "redis.register_function('should_not_exist_func', function() return 456 end)"]
+ assert_equal "should_not_exist_func" [r function load "#!lua name=should_not_exist_func\nredis.register_function('should_not_exist_func', function() return 456 end)"]
assert_equal "OK" [r debug reload nosave]
assert_equal {} [r get should-not-exist]
- assert_equal {{library_name lib1 engine LUA description {} functions {{name func1 description {} flags {}}}}} [r function list]
+ assert_equal {{library_name lib1 engine LUA functions {{name func1 description {} flags {}}}}} [r function list]
if {$functions_only} {
assert_equal 0 [r dbsize]
} else {
diff --git a/tests/integration/replication-4.tcl b/tests/integration/replication-4.tcl
index b8c50308a..281d5a8eb 100644
--- a/tests/integration/replication-4.tcl
+++ b/tests/integration/replication-4.tcl
@@ -47,7 +47,7 @@ start_server {tags {"repl external:skip"}} {
set slave [srv 0 client]
# Load some functions to be used later
- $master FUNCTION load lua test replace {
+ $master FUNCTION load replace {#!lua name=test
redis.register_function{function_name='f_default_flags', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={}}
redis.register_function{function_name='f_no_writes', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={'no-writes'}}
}
diff --git a/tests/integration/replication.tcl b/tests/integration/replication.tcl
index 05f62d5e8..44915be1b 100644
--- a/tests/integration/replication.tcl
+++ b/tests/integration/replication.tcl
@@ -523,10 +523,14 @@ foreach testType {Successful Aborted} {
$replica set mykey myvalue
# Set a function value on replica to check status during loading, on failure and after swapping db
- $replica function load LUA test {redis.register_function('test', function() return 'hello1' end)}
+ $replica function load {#!lua name=test
+ redis.register_function('test', function() return 'hello1' end)
+ }
# Set a function value on master to check it reaches the replica when replication ends
- $master function load LUA test {redis.register_function('test', function() return 'hello2' end)}
+ $master function load {#!lua name=test
+ redis.register_function('test', function() return 'hello2' end)
+ }
# Force the replica to try another full sync (this time it will have matching master replid)
$master multi
@@ -659,7 +663,9 @@ test {diskless loading short read} {
set start [clock clicks -milliseconds]
# Set a function value to check short read handling on functions
- r function load LUA test {redis.register_function('test', function() return 'hello1' end)}
+ r function load {#!lua name=test
+ redis.register_function('test', function() return 'hello1' end)
+ }
for {set k 0} {$k < 3} {incr k} {
for {set i 0} {$i < 10} {incr i} {