You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8 KiB

3 years ago
# @keyv/redis [<img width="100" align="right" src="https://ghcdn.rawgit.org/microlinkhq/keyv/master/media/logo-sunset.svg" alt="keyv">](https://github.com/microlinkhq/keyv)
7 years ago
3 years ago
> Redis storage adapter for [Keyv](https://github.com/microlinkhq/keyv).
7 years ago
TTL functionality is handled directly by Redis so no timestamps are stored and expired keys are cleaned up internally.
7 years ago
## Install
```shell
7 years ago
npm install --save keyv @keyv/redis
7 years ago
```
## Usage
```js
3 years ago
const Keyv = require('keyv')
3 years ago
const keyv = new Keyv('redis://user:pass@localhost:6379')
keyv.on('error', handleConnectionError)
```
Any valid [`Redis`](https://github.com/luin/ioredis#connect-to-redis) options will be passed directly through.
7 years ago
e.g:
7 years ago
```js
3 years ago
const keyv = new Keyv('redis://user:pass@localhost:6379', { disable_resubscribing: true })
7 years ago
```
Or you can manually create a storage adapter instance and pass it to Keyv:
```js
3 years ago
const KeyvRedis = require('@keyv/redis')
const Keyv = require('keyv')
3 years ago
const keyvRedis = new KeyvRedis('redis://user:pass@localhost:6379')
const keyv = new Keyv({ store: keyvRedis })
```
Or reuse a previous Redis instance:
```js
3 years ago
const KeyvRedis = require('@keyv/redis')
const Redis = require('ioredis')
const Keyv = require('keyv')
3 years ago
const redis = new Redis('redis://user:pass@localhost:6379')
const keyvRedis = new KeyvRedis(redis)
const keyv = new Keyv({ store: keyvRedis })
```
7 years ago
## License
3 years ago
**@keyvhq/redis** © [Microlink](https://microlink.io), Released under the [MIT](https://github.com/microlinkhq/keyv/blob/master/LICENSE.md) License.<br/>
Authored and maintained by [Microlink](https://microlink.io) with help from [contributors](https://github.com/microlinkhq/keyv/contributors).
> [microlink.io](https://microlink.io) · GitHub [@MicrolinkHQ](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)