Skip to content

Redis V2

New Redis Instances.

Overview

Previously we had only one Redis instance for all the codops. Now we have added new Redis instances for each codops and added authentication to those instances.

Accessing Redis

get_redis_client_v2 method from the pipe-algorithms library is the prefered way for accessing these new instances.

get_redis_client_v2

get_redis_client_v2 method is used to get the redis client for the specified codops. It takes the following parameters.

  • env : The environment for which the redis client is required. It can be either 'dev' or 'prod'. Default value is 'dev'.

  • codops : The codops for which the redis client is required. CODOPS can also be set as an environment variable named CODOPS

  • password : The password for the redis instance. Password can also be set as an environment variable named CODOPS_{CODOPS}_REDIS_PASSWORD_V2'. So for DEDLR codops you should set the environment variable CODOPS_DEDLR_REDIS_PASSWORD_V2.

Dev and Prod dbs in your instance.

The old approach of specifying a redis url to specify prod or dev db is no longer supported. Instead use the env parameter to specify the environment.

from pipe_algorithms import get_redis_client_v2

redis_dev_client = get_redis_client_v2(env='dev')

# or
# redis_dev_client = get_redis_client_v2()

redis_prod_client = get_redis_client_v2(env='prod')

DEFAULT codops.

Regardless of what CODOPS you work with, you can use the redis instance in the DEFAULT codops.

Using get_redis_client_v2

Tasks, Endpoints and PeachLab enviornments have passwords for YOUR_CODOPS & the DEFAULT codops already injected for you. So you can use the get_redis_client_v2 method without specifying the password.

An example for using get_redis_client_v2 method to fetch your redis instance in a task or an endpoint is shown below.

from pipe_algorithms import get_redis_client_v2
redis_prod_client = get_redis_client_v2(env='prod')

An example for using get_redis_client_v2 method to fetch redis instance in DEFAULT codops for tasks & endpoints is shown below.

from pipe_algorithms import get_redis_client_v2

redis_default_prod_client = get_redis_client_v2(codops='default', env='prod')

Backward Compatibility.

get_redis_client method from the pipe-algorithms library is still supported to seamlessly work with the new redis instances. The intention here is to for backward compatibility and to avoid any breaking changes.

Important Note

The assumption is that all the code using get_redis_client is in production and it will always return the prod redis db for your codops.

from pipe_algorithms import get_redis_client

# important to note the old get_redis_client always returns the new prod instance.
# assumption is that all code using get_redis_client is in production.

new_redis_prod_client = get_redis_client(DEV_URL)
new_redis_prod_client = get_redis_client()
new_redis_prod_client = get_redis_client(PROD_URL)

So if you are developing new code, please use get_redis_client_v2 method to access the new redis instances.

Passwords

There is no need to set any additional passwords, all relevant passwords are already setup for you in all your environments.

Tutorial updates

We will soon update our lab_tutorials repo to use get_redis_client_v2 method.