#Redis Functions From Different Libraries

2 messages · Page 1 of 1 (latest)

stable ridge
#

Hello! Is it possible to call redis functions from different user defined libraries?
As redis disables the required function in the sandboxed lua env, https://redis.io/docs/latest/develop/interact/programmability/lua-api/#:~:text=don't do it.-,Imported Lua modules,-Using imported Lua
I couldn't think of a way to solve or circumvent this.

An e.g. Load both libs

mylib1.lua

#!lua name=mylib1

local function myfunc1(keys, args)
  local res = funcMyLib2
  return res
end

redis.register_function('myfunc1', myfunc1)

mylib2.lua

#!lua name=mylib2

local function myfunc2(keys, args)
  return "Hello from lib2"
end

redis.register_function('myfunc2', myfunc2)

I would like to be able to call myfunc1.

redis-cli FCALL myfunc1 0
(error) ERR user_function:5: Script attempted to access nonexistent global variable 'mylib2' script: myfunc1, on @user_function:5.

Use case:
We want to make mylib2 a general-purpose utility of functions that other libraries can call from their code.

Thank you for your time.
Kindly let me know if any clarification or additional context is required.
Cheers

rain gust
#

Hey @stable ridge ,
I wonder why no to put all the code in one library?
We intentionally did not allow sharing code between library because then it opens the window for planty of versions and compatability issues. For example, what if you update lib1 which is not compatible with lib2 and causes lib2 to break?