Promise-based Redis client
$ npm install --save redis redis-commands then-redis
Then, use as you would anything else:
// using ES6 modules// using CommonJS modulesvar createClient = createClient
To create a client:
// Use the default configconst db =// Or, specify custom config with a URLconst db =// Or, use an object configconst db =
Once you have a client, you're ready to issue some commands. All Redis commands are present on the
Client prototype and may be called with variable length argument lists*. Every command returns a promise for its result. Pipelining happens automatically in most normal usage.
// Simple set, incrby, and getdbdbdb// Multi-key set/getdbdb// Setsdbdb// Hashesvar originalHash = a: 'one' b: 'two'dbdb// Transactionsdbdbdbdb// Pubsubvar subscriber = redissubscribersubscriber
If you don't like the variable-length argument lists, or you already have an array of arguments that you need to pass to a command, you can always call
client.send() directly. It takes two arguments: 1) the name of the Redis command and 2) an array of command arguments.
For best results, it is recommended that you use Redis 2.6 or above.