File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -271,7 +271,9 @@ function VKM.db_size(ctx)
271271 return tonumber (C .ValkeyModule_DbSize (ctx ))
272272end
273273
274- function VKM .random_key (ctx )
274+ function VKM .random_key ()
275+ local ctx = VKM .ctx ()
276+ if ctx == nil then return VKM .ERR end
275277 local rms = C .ValkeyModule_RandomKey (ctx )
276278 if rms == nil then
277279 return nil
Original file line number Diff line number Diff line change @@ -40,17 +40,15 @@ start_server {tags {"scripting-ffi"} overrides {luajit.enable-ffi-api yes}} {
4040 r set " key1" " value1"
4141 r set " key2" " value2"
4242 r eval "
43- local ctx = VKM.ctx()
44- local key = VKM.random_key(ctx)
43+ local key = VKM.random_key()
4544 return type(key)
4645 " 0
4746 } {string }
4847 r del " key1" " key2"
4948
5049 test {FFI - random_key returns nil for empty DB} {
5150 r eval "
52- local ctx = VKM.ctx()
53- local key = VKM.random_key(ctx)
51+ local key = VKM.random_key()
5452 if key == nil then
5553 return 'nil'
5654 else
@@ -62,8 +60,7 @@ start_server {tags {"scripting-ffi"} overrides {luajit.enable-ffi-api yes}} {
6260 test {FFI - random_key returns valid key from DB} {
6361 r set " testkey" " testvalue"
6462 r eval "
65- local ctx = VKM.ctx()
66- local key = VKM.random_key(ctx)
63+ local key = VKM.random_key()
6764 return key
6865 " 0
6966 } {testkey}
You can’t perform that action at this time.
0 commit comments