Hi , How to pass any requirement (redis module) dependency to gear function.
I am trying to read stream data and register to that stream events using redis gear.
Here redis gear function execute on one redis DB , after processing the data need to store the result to another redis database.
Gear function register is in one python script(script.py) and reading it using RG.PYEXECUTE from another python scrpt.
imported redis module dependency in script.py but its throwing redis module not found error. Can you please let me know how to pass requirements to gear function.
This is similar to explained in Introduction to RedisGears | Redis Labs
Error : [âTraceback (most recent call last):\nâ, â File ââ, line 1, in \nâ, âModuleNotFoundError: No module named âredisâ\nâ]
Thanks,
Naresh
The RG.PYEXECUTE
command has an optional REQUIREMENTS
argument. Just list the libraries you want right after the keyword. So, you end up with something like this:
RG.PYEXECUTE "<python code>" REQUIREMENTS numpy pandas whatever
The details are in the RG.PYEXECUTE
command documentation.
Hi, Thank you for the reply.
I am trying to execute the command from python file not from the redis-cli. What ever the command above shared is when we try to execute from cli right.? Please correct my understanding.
Here is the snippet what I am trying .
con = redis.StrictRedis(host=redis_host, port=redis_port, password=redis_password)
script = open(âprocess_redis_stream.pyâ, ârâ).read()
con.execute_command(âRG.PYEXECUTEâ, script, âREQUIREMENTS=redisâ)
Gear function register logic is in âprocess_redis_stream.pyâ which I am reading it from another python file. At this moment I need to to pass the requirements.
but execute_command is only taking two arguments. Invoking from a python client details not given in documentation .Can you please throw some light on this.
Thank You
Naresh.
Update: I am able to pass the requirements to execute command.
con.execute_command(âRG.PYEXECUTEâ, script, âREQUIREMENTSâ, âredisâ)
If you are in proxy network will get connection time out our error.
1 Like