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 in Tasks & Endpoints in production.

Tasks and Endpoints have passwords for yours & 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')

Using get_redis_client_v2 in peach-lab.

We are in the process of automatically injecting passwords into peach-lab. Until then, they need to be manually set.

An example for using get_redis_client_v2 method to fetch redis instance for the SESR codops in peach-lab is shown below.

from pipe_algorithms import get_redis_client_v2

os.environ['CODOPS'] = 'sesr'
os.environ['CODOPS_SESR_REDIS_PASSWORD_V2'] = '***'
redis_sesr_dev_client = get_redis_client_v2()
redis_sesr_prod_client = get_redis_client_v2(env='prod')

An example for using get_redis_client_v2 method to fetch redis instance for the DEFAULT codops in peach-lab is shown below.

from pipe_algorithms import get_redis_client_v2

os.environ['CODOPS_DEFAULT_REDIS_PASSWORD_V2'] = '***'
redis_sesr_dev_client = get_redis_client_v2(codops='default')
redis_sesr_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

Please reach out to the core peach team to get the password for your codops and the default codops.

Tutorial updates

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