Passing requirement(redis module dependency) to gear function

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