Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fixed a bug that prevented getMulti from working correctly.
* Reorganized the Readme.
  • Loading branch information
Ron Korving committed Dec 8, 2011
1 parent 5f9fb66 commit 5742d38
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
54 changes: 27 additions & 27 deletions README.md
Expand Up @@ -5,6 +5,32 @@ Memcached Transactions is a wrapper around
isolated transactional environment for all-or-nothing writes, and smart caching
of previously received, written and deleted data.

## Example

``` javascript
var Memcached = require('memcached');
var MemcachedTransaction = require('memcached-transactions');

var client = new Memcached(['localhost:11211']);
var tr = new MemcachedTransaction(client);

tr.set('foo', 5);
tr.get('foo', function (error, value) {
console.log(value); // outputs 5, even though nothing has been written yet

tr.set('foo', value + 1);

// commit changes to memcached

tr.commit(function (error) {
tr.del('foo');
tr.commit();
});
});
```
Outputs `foo 6`. Note that foo was never set to 5 in memcached. Only on commit
do values ever get created, deleted or updated.

## API

The API tries to follow node-memcached to the letter. The only differences
Expand Down Expand Up @@ -60,35 +86,9 @@ node-memcached currently does not yet implement a touch API, but Memcached
Transactions does. The touch function updates the TTL of a given key. If a
touch operation followed a set() operation, the two will be merged, and the key
that was being set, will receive the TTL that was given by the touch command.
Note that this function only works on Membase, not on Memcached.


## Example

``` javascript
var Memcached = require('memcached');
var MemcachedTransaction = require('memcached-transactions');

var client = new Memcached(['localhost:11211']);
var tr = new MemcachedTransaction(client);

tr.set('foo', 5);
tr.set('bar', 6);
tr.get('foo', function (error, value) {
// value now contains 5, even though nothing has been written yet

value++;
tr.set('foo', value);

tr.commit(function (error) {
console.log('All done');

tr.del('foo');
tr.del('bar');
tr.commit();
});
});
```

## License

Memcached Transactions uses the MIT License.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -79,7 +79,8 @@ MemcachedTransaction.prototype.getMulti = function (keys, cb) {

// for each key, check if we really need to fetch it, or if there is a known state

for (var key in keys) {
for (var i = 0, len = keys.length; i < len; i++) {
var key = keys[i];
var op = this.queue[key];

if (op && op.type === 'del') {
Expand Down

0 comments on commit 5742d38

Please sign in to comment.