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

nodecached

v0.2.0

Published

Memcached server written in node.js. Also contains a client compatible with node-memcached, and can be used as an in-memory cache too.

Downloads

10

Readme

Build Status

nodecached

nodecached is a memcached-compatible server and client written in node.js.

The client is a full-blown driver for any remote memcached servers.

The server is useful if you want a simple memcached server that integrates with your existing node.js infrastructure; otherwise just use the original memcached which is a very lightweight program and blazing fast.

nodecached can also be used as an in-memory cache.

Installation

Installing the package is very simple. Just install globally using npm:

# npm install -g nodecached

On Ubuntu or Mac OS X systems, use sudo:

$ sudo npm install -g nodecached

nodecached Server

nodecached is primarily a server compatible with memcached.

Usage

Start from the command line:

$ nodecached

Options

Options are designed to be compatible with the original memcached, whenever possible.

  • -p port: Start server on the given port.
  • -v: Show notice messages.
  • -vv: Show info messages.
  • -vvv: Show debug messages.

Advanced Options

These options are specific for nodecached.

  • --delay: Enable Nagle's algorithm. Useful for measuring the cost of not setting the option nodelay.
  • --fast: Do not parse commands and return an error on all queries. Useful for measuring socket performance.

Server Commands

nodecached accepts the following commands, based on the original commands:

Storage

There are a few storage commands that start with a header like this:

<command> <key> <flags> <exptime> <bytes>\r\n

  • <command> is set, add, replace, append or prepend.

  • <key> is a string that will identify the element.

  • <flags> is a 32-bit integer to store with the value.

  • <exptime> is expiration time in seconds.

  • <bytes> is the length of the data in bytes.

Afterwards the server will expect the data block:

<data>\r\n

with a length of <bytes>.

The server will respond with:

  • STORED\r\n to indicate success.

  • NOT_STORED\r\n to indicate failure.

Retrieval

The command get has the following syntax:

get <key>\r\n

where <key> is a string that identifies an element.

Deletion

The command to delete a record is:

delete <key>\r\n

where the <key> identifies the record. The server will respond with:

  • DELETED to indicate that the record has been deleted.

  • NOT_DELETED if the value is not found.

Statistics

The following command will retrieve a set of stats.

stats\r\n

The stats include pid, total_items and a few others.

Version

This simple command retrieves the version of nodecached.

version\r\n

The response will be something like this:

VERSION <string>

The version <string> will always start with nodecached-.

Caveats

nodecached may strive to be compatible with memcached, but it is not equivalent. To start with, it will probably consume more memory and be slower -- in my tests about three times as slow.

On the other hand, the absolute difference amounts to about 20 µs per request -- that is 20 millionths of a second. Typical network latencies are about 10 times bigger than that. So the difference might not be an issue to you.

In any case, this is a preliminary version which is not even protocol-complete yet. Please use with care.

Missing commands are: gets, cas, slabs [command], stats [option]. General purpose statistics are by no means complete. The option noreply is not supported yet. UDP and binary protocols are out of scope at the moment.

Memcached Client

nodecached can be used as a client to a remote system. It has been designed to be a drop-in replacement for node-memcached.

Usage

You can integrate nodecached into your code as a client. It is mostly compatible with node-memcached, so it should be a drop-in replacement. Just create a client with a location and options, and use it:

var Client = require('nodecached').Client;
var client = new Client('localhost:11311', {
	timeout: 3000,
});

API

The API has the following functions.

Client(location, options, callback)

Create the client.

  • location: a string with the location host:port. Can also be an array of locations, or an object with {location: weight}. Note: weights are ignored right now.

client.get(key, callback)

Retrieve an object from the server by key, and send to the callback.

  • key: a string with the memcached key.
  • callback: function(error, value) to call with the retrieved value.

client.set(key, value, lifetime, callback)

Store an object in the server by key.

  • key: a string with the memcached key.
  • value: the object to store.
  • lifetime: max seconds to store.
  • callback: function(error, result) to call, true if stored.

client.delete(key, callback)

Delete an object from the server by key.

  • key: a string with the memcached key.
  • callback: function(error, result) to call, true if deleted, false otherwise.

client.incr(key, value, callback)

Increment a numeric value from the server by key.

  • key: a string with the memcached key.
  • value: the value to add to the original.
  • callback: function(error, result) to call with the incremented value, or false if not found.

client.decr(key, value, callback)

Decrement a numeric value from the server by key.

  • key: a string with the memcached key.
  • value: the value to substract from the original.
  • callback: function(error, result) to call with the decremented value, or false if not found.

Options

The client accepts some options compatible with node-memcached.

  • timeout: ms to wait for a response from the server.

In-memory Cache

nodecached can also work as an in-memory cache, again compatible with node-memcached.

References

License

Distributed under the MIT license. See the file LICENSE for details.