@am92/redis
v2.0.4
Published
Redis SDK
Downloads
98
Readme
@am92/redis
This is an SDK Wrapper which provides Redis functionalities to interact with a Redis Instance. This package uses Node-Redis package using its v4.x.x version.
This package provides the following functionalities:
- Redis Connection Helper
- Redis SDK Class
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_KEY_PREFIX=
export REDIS_AUTH=
Note:
- If 'REDIS_ENABLED' is set to 'true', 'REDIS_HOST' and 'REDIS_PORT' are required
- If 'REDIS_AUTH_ENABLED' is set to 'true', 'REDIS_AUTH'is required
- 'REDIS_KEY_PREFIX' prepends all redis keys with the specified value
Creating a Redis SDK Instance
import { RedisSdk } from '@am92/redis'
const redisSdk = new RedisSdk()
export default redisSdk
If you wish to pass your custom 'config' for the RedisSdk, then you can build it as follows: Note: You will have to call the redisSdk.connect() to establish a connection before using the RedisSdk Methods
import { RedisSdk } from '@am92/redis'
const config = {
CONNECTION_CONFIG: {
socket: {
host: '',
port: 6379,
tls: true
},
password: ''
}
KEY_PREFIX: ''
}
const redisSdk = new RedisSdk(config)
export default redisSdk
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)