From 06380e5fe18b92edd10c37c232d68f78a080a137 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran <105669860+msotheeswaran@users.noreply.github.com> Date: Tue, 14 Mar 2023 13:45:29 -0700 Subject: [PATCH] Add KeyDB global variable to lua api (#606) --- src/scripting.cpp | 3 +++ tests/unit/scripting.tcl | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/scripting.cpp b/src/scripting.cpp index 3995eb8f2..f1772cd5c 100644 --- a/src/scripting.cpp +++ b/src/scripting.cpp @@ -1264,6 +1264,9 @@ void scriptingInit(int setup) { /* Finally set the table as 'redis' global var. */ lua_setglobal(lua,"redis"); + /* Set table as 'keydb' global var as well */ + lua_getglobal(lua,"redis"); + lua_setglobal(lua,"keydb"); /* Replace math.random and math.randomseed with our implementations. */ lua_getglobal(lua,"math"); diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index e8454ef1d..561bcf7e1 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -43,10 +43,15 @@ start_server {tags {"scripting"}} { r eval {return redis.call('get',KEYS[1])} 1 mykey } {myval} - test { EVAL - keys command works? } { + test {EVAL - keys command works? } { r eval {return redis.call('keys', 'test')} 0 } + test {EVAL - KeyDB global works } { + r eval {return keydb.call('get', KEYS[1])} 1 mykey + assert_equal [r eval {return redis.call('get',KEYS[1])} 1 mykey] [r eval {return keydb.call('get', KEYS[1])} 1 mykey] + } + test {EVALSHA - Can we call a SHA1 if already defined?} { r evalsha fd758d1589d044dd850a6f05d52f2eefd27f033f 1 mykey } {myval}