From eca505a608694a2caaf8dd3fb18cb553aa8cdd53 Mon Sep 17 00:00:00 2001 From: Harmen Date: Fri, 5 Feb 2021 21:34:47 +0100 Subject: [PATCH] set the selected DB in lua --- integration/script_test.go | 9 +++++++++ lua.go | 1 + 2 files changed, 10 insertions(+) diff --git a/integration/script_test.go b/integration/script_test.go index 4f110a78..aea779b6 100644 --- a/integration/script_test.go +++ b/integration/script_test.go @@ -196,6 +196,15 @@ func TestLua(t *testing.T) { "EVAL", `return cjson.decode(1, 2)`, "0", ) }) + + // selected DB gets passed on to lua + testRaw(t, func(c *client) { + c.Do("SELECT", "3") + c.Do("EVAL", "redis.call('SET', 'foo', 'bar')", "0") + c.Do("GET", "foo") + c.Do("SELECT", "0") + c.Do("GET", "foo") + }) } func TestLuaCall(t *testing.T) { diff --git a/lua.go b/lua.go index 2515a63e..7a99252f 100644 --- a/lua.go +++ b/lua.go @@ -19,6 +19,7 @@ func mkLuaFuncs(srv *server.Server, c *server.Peer) map[string]lua.LGFunction { pCtx.authenticated = true } pCtx.nested = true + pCtx.selectedDB = getCtx(c).selectedDB return func(l *lua.LState) int { top := l.GetTop()