@thzero/library_server_repository_redis_ioredis
v0.19.1
Published
  [ and nothing else; everything in the base is inherited unchanged.
Two connection shapes are supported, chosen by whether connectionInfo.port is set:
| connectionInfo | Built as |
|---|---|
| has a port | new Redis({ port, host, username, password, db, enableReadyCheck: false }) |
| anything else | new Redis(connectionInfo, { enableReadyCheck: false }) — so a connection string or a full ioredis options object passes straight through |
enableReadyCheck is forced to false in both cases. Some managed Redis providers do not permit the INFO command that the ready check issues.
openSource.js — a default-exported function returning the licence manifest for this package and its dependencies, for an application's open-source attribution page.
Configuration
Read by the base from db.redis.connection:
{
"app": {
"db": {
"redis": {
"connection": {
"host": "127.0.0.1",
"port": 6379,
"username": "<username>",
"password": "<password>",
"db": 0
}
}
}
}
}Or as a connection string, which takes the second branch above:
{ "app": { "db": { "redis": { "connection": "redis://user:[email protected]:6379/0" } } } }Override getClientName() to read a different db.* block.
Wiring it up
import BaseRedisRepository from '@thzero/library_server_repository_redis_ioredis/index.js';
class RegistryRepository extends BaseRedisRepository {
async publish(correlationId, channel, message) {
const client = await this._getClient(correlationId);
await client.publish(correlationId, channel, JSON.stringify(message));
}
}Register it with the injector from _initRepositories in your BootMain derived class, or from a boot plugin's initRepositories.
A note on error handling
_initializeClientConnection returns the client as ioredis constructs it, with no error listener attached. ioredis emits error on a failed or dropped connection, and an unhandled error event terminates the process — attach a handler in your subclass if you want the application to survive Redis being unreachable.
Development
npm run lint # eslint .
npm run lint:fix # eslint . --fix
npm test # node --test "test/*.test.js"
