https://github.com/kth/kth-node-redis
Redis client module for Node.js. Everything with Promises!
https://github.com/kth/kth-node-redis
Last synced: 10 months ago
JSON representation
Redis client module for Node.js. Everything with Promises!
- Host: GitHub
- URL: https://github.com/kth/kth-node-redis
- Owner: KTH
- License: mit
- Created: 2016-09-02T11:39:38.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2024-12-01T04:14:39.000Z (over 1 year ago)
- Last Synced: 2024-12-06T16:43:25.366Z (over 1 year ago)
- Language: JavaScript
- Size: 438 KB
- Stars: 2
- Watchers: 19
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kth-node-redis
Redis client module for Node.js. (Everything with Promises)
## Usage
```javascript
const redis = require('kth-node-redis')
// basics
redis('default', {
/* optional redis client config */
})
.then(function (client) {
return client.getAsync('key')
})
.then(function (value) {
// do something with value
})
.catch(function (err) {
// handle error
})
// multi
redis('default', {
/* optional redis client config */
})
.then(function (client) {
return client.multi().hmset('foo', { value: 'bar' }).expire('foo', 30).hgetall('foo').execAsync()
})
.then(function (results) {
// results[1] => 'OK'
// results[1] => 1
// results[2] => { value: 'bar' }
// results will depend on what commands are executed
})
.catch(function (err) {
// handle error
})
// quit if needed
redis.quit('default')
```
## Options
- `name` optional name, defaults to `default`. Use the same name to get
the same client instance or re-create it. Use a new name to create a
new instance.
- `options` optional config for the Redis client. Has a default retry
strategy. See below for details. For info about the Redis client
options, see https://www.npmjs.com/package/redis.
## Default retry strategy
```js
function retry_strategy(options) {
if (options.error.code === 'ECONNREFUSED') {
return new Error('Connection refused by server.')
}
if (options.total_retry_time > 1000 * 60 * 60) {
return new Error('Retry time exhausted')
}
if (options.times_connected > 10) {
return undefined
}
return Math.max(options.attempt * 100, 3000)
}
```