loopbackio / loopback-connector-redis

EXPERIMENTAL: Redis connector for LoopBack.
http://loopback.io/doc/en/lb2/Redis-connector.html
Other
36 stars 46 forks source link

How to set Redis database number? #62

Open bivanychko-intobi opened 4 years ago

bivanychko-intobi commented 4 years ago

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

jhimy-michel commented 3 years ago

did you manage to fix this?

arnaud16571542 commented 2 years ago

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); }