redis-simple-connect
(ANOTHER) simple Node.js module to connect and send commands to Redis using promises with configurable environment variables, build on top of Node Redis.
Features
- Connect easily to Redis using promises and async/await
- Use environment variables or an options object to set connection parameters
- Call async commands like
GET
andSET
usinggetAsync
andsetAsync
methods
How to use
$ npm i -s redis-simple-connect
const connectRedis = ; const client = await ;
Reference
Connecting to Redis
When calling the main exported method from module, you may use environment variables or an options object.
The method returns a RedisClient
object from Node Redis, so you can call this class methods and commands.
With environment variables
const client = await ;
This way the module will try to obtain the main connection parameters (host, port, password and database number) from the following variables: REDIS_HOST
, REDIS_PORT
, REDIS_PASSWORD
and REDIS_DB
.
- Note that port, password and database number are not required options.
If you want to add a prefix to the variables, you may use the envPrefix
parameter:
const client = await ; // This way the method will look for `MYAPP_REDIS_HOST`, `MYAPP_REDIS_PORT`, etc.
With an options object
const client = await ;
getAsync and setAsync
This module injects two methods to the RedisClient
class: getAsync
and setAsync
.
Both are promisifed versions of the respective methods get
and set
.
const value = await client; await client;