Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adriano-di-giovanni/node-redis-multi
A Node.js library to augment node_redis interface with an enhanced version of MULTI command.
https://github.com/adriano-di-giovanni/node-redis-multi
Last synced: 1 day ago
JSON representation
A Node.js library to augment node_redis interface with an enhanced version of MULTI command.
- Host: GitHub
- URL: https://github.com/adriano-di-giovanni/node-redis-multi
- Owner: adriano-di-giovanni
- Created: 2015-05-07T14:24:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-10T06:28:53.000Z (over 9 years ago)
- Last Synced: 2024-10-16T00:33:17.799Z (29 days ago)
- Language: JavaScript
- Size: 121 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-redis-multi
A Node.js library to augment [node_redis](https://github.com/mranney/node_redis) with an enhanced version of MULTI command.
## Installation
```
npm install node-redis-multi --save
```## Usage
`node-redis-multi` replaces methods that are related to `MULTI`.
The callback of `.exec()` will get invoked with two arguments as the original version but second argument is a [`Response`](#response) object.
```javascript
// module deps
var
redis = require('redis');require('../lib/multi')(redis);
var
client = redis.createClient(),
multi = client.multi();multi
.set('path:to:key', 1)
.get('path:to:key')
.exec(function (error, response) {
console.log(response.get('path:to:key')); // 1
console.log(response.at(0)); // OK
console.log(response.at(1)); // 1
});
```Response object lets you query replies from `.exec()` using two different methods: `Response#get()` and `Response#at()`.
`Response#get()` lets you retrieve a reply by key:
```javascript
multi
.set('path:to:key', 'value')
.get('path:to:key')
.exec(function (error, response) {var
reply = response.get('path:to:key');console.log(reply); // value
});
````Response#get()` is applicable only if the issued command has
* arity > 0;
* `readonly` flag;
* position of first key === 1;
* position of last key === 1.See Redis [COMMAND](http://redis.io/commands/command) for further information.
`Response#at()` lets you retrieve a reply by its index:
```javascript
multi
.set('path:to:key', 'value')
.get('path:to:key')
.exec(function (error, response) {var
reply = response.at(1);
console.log(reply); // value
});
```