@am92/redis v3.0.1
@am92/redis
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
- Environment Variables
- Creating an Instance
- Self-managed Config
- Connection Management
- Contributors
- Resources
- License
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 Name | Required | Default | Description |
---|---|---|---|
REDIS_ENABLED | No | false | Enables/Disables Redis functionality |
REDIS_AUTH_ENABLED | No | false | Enables/Disables Redis authentication |
REDIS_HOST | No* | - | Redis server host address |
REDIS_PORT | No* | - | Redis server port number |
REDIS_AUTH | No** | - | Redis authentication password |
REDIS_KEY_PREFIX | No | - | Prefix to be added to all Redis keys |
REDIS_PING_INTERVAL | No | 1800000 (30 minutes) | Ping interval in milliseconds |
Note:
- * - Required fields if
REDIS_ENABLED
is set totrue
. - ** - Required fields if
REDIS_AUTH_ENABLED
is set totrue
.
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
7 months ago
10 months ago
7 months ago
6 months ago
6 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago