@tadashi/connect-redis
v3.0.0
Published
Simplifying Redis connection
Downloads
21
Readme
connect-redis
Simplifying Redis connection
Install
$ npm i -S @tadashi/connect-redis
API
There are two ways to connect:
connect([opts])
Connects to a Redis server or cluster.
singleton([opts])
Connects to a Redis instance or cluster as a singleton.
| parameter | type | required | default | description | | --------- | ----------- | -------- | ------------------ | ----------------- | | opts | Object | no | see below | See configuration options |
opts
| parameter | type | required | default | description | | -------------- | ---------------- | -------- | -------------- | --------------------------------------- | | address | String|String[] | no | 127.0.0.1:6379 | The address or addresses of the Redis server(s). | | password | String | no | - | The password for authenticating with the Redis server, if required. | | clusterOptions | Object | no | - | See configuration options |
Cluster
To use Cluster
, set addresses separated by commas or an array and set clusterOptions.
import {connect} from '@tadashi/connect-redis'
const redis = connect({
address: '127.0.0.1:6379, 127.0.0.1:6380, 127.0.0.1:6381',
// or
address: ['127.0.0.1:6379', '127.0.0.1:6380', '127.0.0.1:6381'],
// and
clusterOptions: {
retryDelayOnClusterDown: 500,
// ...
}
})
Usage
import {connect} from '@tadashi/connect-redis'
const redis = connect()
await redis.set('a', 'xxx')
const result = await redis.get('a')
console.log(result) // => xxx
Buy Me a Coffee
BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4
License
MIT © Thiago Lagden