supports custom redis database number by passing REDIS_DB to env

This commit is contained in:
jcsaaddupuy
2022-02-12 00:44:55 +01:00
parent cff9e69446
commit 074b91f633
2 changed files with 3 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ if jh.is_jesse_project():
ENV_VALUES['POSTGRES_PASSWORD'] = 'password'
ENV_VALUES['REDIS_HOST'] = 'localhost'
ENV_VALUES['REDIS_PORT'] = '6379'
ENV_VALUES['REDIS_DB'] = 0
ENV_VALUES['REDIS_PASSWORD'] = ''
# validation for existence of .env file

View File

@@ -12,6 +12,7 @@ async def init_redis():
return await aioredis.create_redis_pool(
address=(ENV_VALUES['REDIS_HOST'], ENV_VALUES['REDIS_PORT']),
password=ENV_VALUES['REDIS_PASSWORD'] or None,
db=int(ENV_VALUES.get('REDIS_DB') or 0),
)
@@ -21,7 +22,7 @@ if jh.is_jesse_project():
if not jh.is_notebook():
async_redis = asyncio.run(init_redis())
sync_redis = sync_redis_lib.Redis(
host=ENV_VALUES['REDIS_HOST'], port=ENV_VALUES['REDIS_PORT'], db=0,
host=ENV_VALUES['REDIS_HOST'], port=ENV_VALUES['REDIS_PORT'], db=int(ENV_VALUES.get('REDIS_DB') or 0),
password=ENV_VALUES['REDIS_PASSWORD'] if ENV_VALUES['REDIS_PASSWORD'] else None
)