Redis module for the Hapiness framework.
$ npm install --save @hapiness/core @hapiness/redis rxjs
or
$ yarn add @hapiness/core @hapiness/redis rxjs"dependencies": {
"@hapiness/core": "^1.3.0",
"@hapiness/redis": "^1.0.1",
"rxjs": "^5.5.5",
//...
}
//...This module provide an Hapiness extension for Redis.
To use it, simply register it during the bootstrap step of your project and provide the RedisExt with its config
@HapinessModule({
version: '1.0.0',
providers: [],
declarations: [],
imports: [RedisModule]
})
class MyApp implements OnStart {
constructor() {}
onStart() {}
}
Hapiness
.bootstrap(
MyApp,
[
/* ... */
RedisExt.setConfig(
{
url: '//redis_url:6379',
password: 'password',
db: '1'
/* ... Other options ... */
}
)
]
)
.catch(err => {
/* ... */
});RedisExt needs a ClientOpts object so you can provide all the properties defined in the interface (see below)
export interface ClientOpts {
host?: string;
port?: number;
path?: string;
url?: string;
parser?: string;
string_numbers?: boolean;
return_buffers?: boolean;
detect_buffers?: boolean;
socket_keepalive?: boolean;
no_ready_check?: boolean;
enable_offline_queue?: boolean;
retry_max_delay?: number;
connect_timeout?: number;
max_attempts?: number;
retry_unfulfilled_commands?: boolean;
auth_pass?: string;
password?: string;
db?: string;
family?: string;
rename_commands?: { [command: string]: string };
tls?: any;
prefix?: string;
retry_strategy?: RetryStrategy;
ping_keepalive_interval?: number: // In seconds
}
To use redis, you need to inject inside your providers the RedisClientService.
class FooProvider {
constructor(private _redis: RedisClientService) {}
bar(): Observable<string> {
return this._redis.connection.get('my_key');
}
}RedisClientService.connection this will return you the redis client and you will be able to call on it every redis command (see the list of commands here)
INFO All function returns RxJS Observable
| Julien Fauville | Antoine Gomez | Sébastien Ritz | Nicolas Jessel |
Copyright (c) 2017 Hapiness Licensed under the MIT license.