Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

@hapiness/redis

1.4.1 • Public • Published
Hapiness

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

Back to top

Maintainers

tadaweb
Julien Fauville Antoine Gomez Sébastien Ritz Nicolas Jessel

Back to top

License

Copyright (c) 2017 Hapiness Licensed under the MIT license.

Back to top

install

npm i @hapiness/redis

Downloadsweekly downloads

3

version

1.4.1

license

SEE LICENSE IN https://github.com/hapinessjs/redis-module/blob/master/LICENSE.md

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability