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:
$ npm install --save @am92/redis
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:
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)
Ankit Gandhi |
Mehul Agarwal |