Skip to content

Commit

Permalink
set the selected DB in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
alicebob committed Feb 17, 2021
1 parent 653d2da commit eca505a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions integration/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit eca505a

Please sign in to comment.