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

ali-mc

v1.3.0

Published

AliCloudDB for Memcache client

Downloads

19

Readme

ali-mc

AliCloudDB for Memcache client. A standard implemetation of memcached binary protocol, and is compatible with spymemcached-2.12.0.jar.

NPM version build status coverage David deps

Install

npm install ali-mc --save

Usage

new MCClient(options)

Create a mc client instance.

Parameters:

  • {object} options
    • {String} host
    • {Integer} port
    • {String} [username]
    • {String} [password]
    • {String} [protocol]

Example:

const MCClient = require('ali-mc');
const mc = new MCClient({
  host: ${host},
  port: ${port},
  username: ${username},
  password: ${password},
  // protocol: ${protocol}, // default is `binary`, also can use `text`
  // responseTimeout: 50,
  // logger: console,
});

.ready(callback)

If the client is ready for services, callback function will be called.

Otherwise all method will return The server is not available!;

.get(key[, callback])

Get the item with specified key.

Parameters:

  • {String} key
  • {function(err, value)} [callback]

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

Example:

// call with callback
mc.get(${someKey}, function(err, value) {
  if (err) {
    return console.log(err);
  }
  console(value);
});

// call without callback
const co = require('co');
co(function *() {
  try {
    let value = yield mc.get(${someKey});
    console.log(value);
  } catch(err) {
    console.log(err);
  }
});

.set(key, value[, expired, callback])

.add(key, value[, expired, callback])

.replace(key, value[, expired, callback])

Set should store the data unconditionally if the item exists or not. Add MUST fail if the item already exist. Replace MUST fail if the item doesn't exist.

Parameters:

  • {String} key
  • {object} value - anything except for function, null and undefined
  • {UnsignedInteger} [expired = 0] - in seconds
  • {function(err)} [callback]

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

.delete(key[, callback])

Delete the item with specified key.

Parameters:

  • {String} key
  • {function(err)} [callback]

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

.increment(key[, step, callback])

.decrement(key[, step, callback])

Add or remove the specified amount to the requested counter.

Increment will cause the counter to wrap if it is up to the max value of 64 bit unsigned int.

Decrement will never result in a "negative value" (or cause the counter to "wrap")

Parameters:

  • {String} key
  • {PostiveInteger|UnsignedLong|object} [step = 1] - amount to add or remove. An object could be passed in to specify more details:
    • {UnsignedInteger|UnsignedLong} [step = 1]
    • {UnsignedInteger|UnsignedLong} [initial = 1] - initial value
    • {UnsignedInteger} [expired = 0] - in seconds
  • {function(err, value)} [callback] - the returned value is an instance of unsigned Long. If the item doesn't exist, the server will respond with the initial value.

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

Example:

mc.increment(${someKey}, function(err, value) { ... });

// above is equal to
mc.increment(${someKey}, 1, function(err, value) { ... });

// also is equal to
mc.increment(${someKey}, {
  step: 1,
}, function(err, value) { ... });

.flush([expired, callback])

Flush the items in the cache now or some time in the future as specified by the "expired" field.

Parameters:

  • {UnsignedInteger} [expired = 0] - in seconds
  • {function(err)} [callback]

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

.version([callback])

Request the server version.

Parameters:

  • {function(err, value)} [callback] - the value is a version string

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

.append(key, value[, callback])

.prepend(key, value[, callback])

Append or prepend the specified value to the requested key.

Parameters:

  • {String} key
  • {String|Buffer} value
  • {function(err)} [callback]

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

Example:

// appends "!" to the "Hello" key
mc.append('Hello', '!', function(err) { ... });

.touch(key[, expired, callback])

Change the item's expiration.

Parameters:

  • {String} key
  • {UnsignedInteger} [expired = 0] - in seconds
  • {function(err)} [callback]

Return:

  • {mc|thunk} returns the mc instance if the callback is passed in, or return the thunk.

.gat(key[, expired, callback])

All the same with .touch() except this it will return the value of the spcified key. Text protocol not support

.close()

Close the client, you should listen the 'close' event to confirm that the client closes.

Event: 'error'

Emitted when an error occurs.

Parameters:

  • {Error} err - error object

Event: 'close'

Emitted when the client closes.

References


The MIT License (MIT) Copyright (c) 2016 fool2fish [email protected] and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.