Giter VIP home page Giter VIP logo

meteor-memjs's Introduction

aheissenberger:memjs

A Meteor wrapper for MemJS a pure Node.js client library for using memcache, in particular, the MemCachier service. It uses the binary protocol and support SASL authentication.

MemCachier is the Memcache Add-On provided by cloudcontroll which supports Meteor hosting with a custom buildpack.

Dependencies

  • memjs - A memcache client for node using the binary protocol and SASL authentication

Installation

Install using Meteor:

meteor add aheissenberger:memjs

Quick Start

Using it is straight-forward as memjs understands the MEMCACHIER_SERVERS, MEMCACHIER_USERNAME and MEMCACHIER_PASSWORD environment variables.

var client = new MemJS()
client.set('hello', 'world', 600);
var result = client.get('hello');
console.log(result.toString());

Documentation can be found here: http://amitlevy.com/projects/memjs/

API

Settings Values

client.set('hello', 'world', 600);

The set(key, val, expiration) function accepts the following parameters.

  • key: key to set
  • val: value to set
  • expiration [optional]: time interval, in seconds, after which memcached will expire the object

return

  • true if successful
  • will throw an error of something goes wrong

Getting Values

client.get('hello', function(err, val) {

});

The get(key) function accepts the following parameters.

  • key: key to retrieve

return

  • value (Buffer Object) if successful - you need to convert it back to a String
  • null if key does not exist
  • will throw an error of something goes wrong

all methodes

function returns description
new MemJS( server, options ) Connection Object initializes connection to Memcachier
get( key ) value get value for key, null if key does not exist
set( key, value, expire ) success set/overrides value of key
add( key, value, expire ) success set value of key, fails if key exists
replace( key, value, expire ) success set value of key, fails if key exists
delete( key ) success deletes key
increment( key, amount, expire ) value returns the value after the increment
decrement( key, amount, expire ) success returns the value after the decrement - success if OK - this is different to increment!!
stats( ) {server, stats} Fetches memcache stats from each connected server
flush( ) {lastErr, results} Flushes the cache on each connected server
close( ) success Closes connections to all the servers

input: value will allways coverted to string - you can change this with this option output: value will allways be a Buffer Value - use to String to covert it

expire is optional, default can be set as option of new MemJS call

Configuration

MemJS understands the following environment variables:

  • MEMCACHIER_SERVERS - used to determine which servers to connect to. Should be a comma separated list of [hostname:port].
  • MEMCACHIER_USERNAME - if present with MEMCACHIER_PASSWORD, MemJS will try to authenticated to the server using SASL.
  • MEMCACHIER_PASSWORD - if present with MEMCACHIER_USERNAME, MemJS will try to authenticated to the server using SASL.
  • MEMCACHE_USERNAME - used if MEMCACHIER_USERNAME is not present
  • MEMCACHE_PASSWORD - used if MEMCACHIER_PASSWORD is not present

Environment variables are only used as a fallback for explicit parameters.

specific Option of the Wrapper

var client = new MemJS('USERNAME:PASSWORD@SERVER:PORT',{EJSON:true});

The EJSON:true allows to store and retrieve Javascript Objects - please check Meteor EJSON for more information. $ meteor add ejson is required to use this option

Changelog

v0.0.3

  • fix memjs.js loading on client

v0.0.2

  • Convert Numbers to Strings

v0.0.1

  • Initial release

Copyright and license

Copyright © 2015 Andreas Heissenberger

aheissenberger:memjs is licensed under the MIT license.

meteor-memjs's People

Contributors

aheissenberger avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

kaldr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.