loopback-connector-redis icon indicating copy to clipboard operation
loopback-connector-redis copied to clipboard

How to set Redis database number?

Open bivanychko-intobi opened this issue 5 years ago • 2 comments

Out of the box, a Redis instance supports 16 logical databases. These databases are effectively siloed off from one another, and when you run a command in one database it doesn’t affect any of the data stored in other databases in your Redis instance. Redis databases are numbered from 0 to 15 and, by default, you connect to database 0 when you connect to your Redis instance. However, you can change the database you’re using with the select command after you connect: 127.0.0.1:6379 > select 15 127.0.0.1:6379[15] > ...

So my question is next: how can I set this db number for my redis instance in loopback? I saw that in redis connector config there is property called 'database' but I am not sure if it's the property I am looking for

bivanychko-intobi avatar Oct 09 '20 09:10 bivanychko-intobi

did you manage to fix this?

jhimy-michel avatar Mar 01 '21 13:03 jhimy-michel

You are correct : the 'database' property is what you are looking. Check below my redis.datasource.ts

@lifeCycleObserver('datasource') export class RedisDataSource extends juggler.DataSource implements LifeCycleObserver { static dataSourceName = 'redis';

constructor( @inject('datasources.config.redis', { optional: true }) dsConfig: object = { ...config }, ) { // Override data source config from environment variables Object.assign(dsConfig, { host: process.env.REDIS_HOST, port: process.env.REDIS_PORT, password: process.env.REDIS_PASSWORD, db: process.env.REDIS_DATABASE, url: process.env.REDIS_URL, }); super(dsConfig); }

arnaud16571542 avatar Feb 19 '22 22:02 arnaud16571542