Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsumners/abstract-cache-redis
https://github.com/jsumners/abstract-cache-redis
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jsumners/abstract-cache-redis
- Owner: jsumners
- Created: 2017-11-23T20:00:25.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-13T22:37:11.000Z (over 3 years ago)
- Last Synced: 2024-09-21T11:41:40.045Z (about 2 months ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 7
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# abstract-cache-redis
This module provides a cache client that is compliant with the
[abstract-cache](https://github.com/jsumners/abstract-cache) protocol. This
client implements the `await` style of the protocol.In addition to the API mandated by the protocol, the client exposes
`keys`, `scan`, `scanStream`, `disconnect` and `quit` methods. These map to the
[ioredis](https://npm.im/ioredis) methods of the same names. The `disconnect`
and `quit` methods are only useful if you create the client with connection
configuration instead of an already connected Redis client.## Example
```js
// Create a client that uses ioredis to connect to `localhost:6379`.
const client = require('abstract-cache-redis')({ioredis: {}})client.set('foo', 'foo', 1000)
.then(() => client.has('foo'))
.then(console.log) // true
.then(() => client.quit())
.catch(console.error)client.set('foo', 'foo', 1000)
.then(() => client.keys('fo*'))
.then(console.log) // [ 'foo' ]
.then(() => client.quit())
.catch(console.error)
```## Options
The client factory accepts the an object with the following properties:
+ `client`: An already connected instance of `ioredis`.
+ `ioredis`: A regular `ioredis` configuration object.Notes:
1. `client` takes precedence to `ioredis`.
1. At least one of the `client` or `ioredis` properties must be supplied.
1. The user is responsible for closing the connection.## Tests
In order to run the tests for this project a local instance of Reis must
be running on port `6379`. A `docker-compose.yml` is included to facilitate
this:```shell
$ docker-compose -d up
$ tap test/*.test.js
````npm test` automates the above.
## License
[MIT License](http://jsumners.mit-license.org/)