Package Exports
- @hapiness/redis
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hapiness/redis) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Redis Module
Redis module for the Hapiness framework.
Table of contents
Using your module inside Hapiness application
yarn or npm it in your package.json
$ 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",
//...
}
//...Importing RedisModule from the library
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
}
Using Redis inside your application
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 functions
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
Maintainers
| Julien Fauville | Antoine Gomez | Sébastien Ritz | Nicolas Jessel |
License
Copyright (c) 2017 Hapiness Licensed under the MIT license.