3.0.1 • Published 6 months ago

@am92/redis v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@am92/redis

npm version  Security: Snyk  License: MIT  Downloads Bundle Size

This is an SDK wrapper that simplifies interaction with a Redis instance by providing convenient Redis functionalities. It is built on top of the Node-Redis package (v4.7.x).

For full documentation, visit here.

Table of Content

Installation

npm install --save @am92/redis

Environment Variables

The following environment variables need to be set to work with this package:

##### Redis Config
export REDIS_ENABLED=false
export REDIS_AUTH_ENABLED=false
export REDIS_HOST=
export REDIS_PORT=
export REDIS_AUTH=
export REDIS_KEY_PREFIX=
export REDIS_PING_INTERVAL=
Variable NameRequiredDefaultDescription
REDIS_ENABLEDNofalseEnables/Disables Redis functionality
REDIS_AUTH_ENABLEDNofalseEnables/Disables Redis authentication
REDIS_HOSTNo*-Redis server host address
REDIS_PORTNo*-Redis server port number
REDIS_AUTHNo**-Redis authentication password
REDIS_KEY_PREFIXNo-Prefix to be added to all Redis keys
REDIS_PING_INTERVALNo1800000 (30 minutes)Ping interval in milliseconds

Note:

  • * - Required fields if REDIS_ENABLED is set to true.
  • ** - Required fields if REDIS_AUTH_ENABLED is set to true.

Creating an Instance

import { RedisSdk } from '@am92/redis'

const redisSdk = new RedisSdk()

export default redisSdk

Note: You do not need to set any environment variables if you wish to pass your own config.

Self-managed Config

If you wish to pass your custom 'config' for the RedisSdk, then you can avoid setting any environment variables defined above and pass your own redis config as follows:

import { RedisSdk } from '@am92/redis'

const config = {
  CONNECTION_CONFIG: {
    socket: {
      host: '',
      port: 6379,
      tls: true
    },
    password: '',
    pingInterval: 0
  },
  KEY_PREFIX: ''
}

const redisSdk = new RedisSdk(config)

export default redisSdk

Connection Management

To manage redis connections for RedisSdk Instances, connect and disconnect methods are provided and they can be called as shown below. The connect method must be called before before using the RedisSdk Methods.

// To establish a connection
await redisSdk.connect()

// To release the connection
await redisSdk.disconnect()

// To force release the connection
await redisSdk.disconnect(true)

Contributors

Resources

License

2.1.1

7 months ago

2.0.5

10 months ago

2.1.0

7 months ago

3.0.1

6 months ago

3.0.0

6 months ago

2.0.4

1 year ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.1

3 years ago

1.1.2

2 years ago

1.1.0

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.0

3 years ago