npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

memcached-transactions

v0.1.1

Published

A transactional wrapper around 3rdEden's node-memcached library.

Downloads

5

Readme

Memcached Transactions

Memcached Transactions is a wrapper around node-memcached. It provides an isolated transactional environment for all-or-nothing writes, and smart caching of previously received, written and deleted data.

Example

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 are:

new MemcachedTransaction(memcachedClient, [options])

Where options is an optional object containing:

simulate (boolean)

If true does not write anything to the memcached server on commit, but instead outputs all scheduled operations to console. This way operation bundling and discarding can be inspected for correctness.

debug (boolean, function)

If true outputs every memcached operation to console. If debug is a function, that function will be called (with a variable number of arguments) whenever debug information is output.

myTransaction.commit([cb])

Executes all scheduled write operations. On completion, the optional callback cb is called.

myTransaction.rollBack([cb])

Discards all scheduled write operations and calls the optional callback cb on completion. This function is however not asynchronous, so the callback may safely be omitted. It is simply provided as a convenient exit point that is similar to the callback in the commit function.

API: transactional node-memcached wrappers

The following wrapper functions are available. General rule is that write functions are queued and merged for commit, and read functions only read that what has not yet been retrieved or overwritten within this transaction.

myTransaction.get(key, [cb])

myTransaction.getMulti(keys, [cb])

myTransaction.set(key, value, [ttl, cb])

Since writes are queued, the callback cb is provided only for compatibility.

myTransaction.del(key, [cb])

Since writes are queued, the callback cb is provided only for compatibility.

myTransaction.touch(key, [ttl, cb])

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.

License

Memcached Transactions uses the MIT License.