GithubHelp home page GithubHelp logo

alanjrogers / memcached Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arthurnn/memcached

1.0 1.0 0.0 11.75 MB

A Ruby interface to the libmemcached C client

Home Page: http://blog.evanweaver.com/files/doc/fauna/memcached/

License: Academic Free License v3.0

Ruby 100.00%

memcached's Introduction

memcached

An interface to the libmemcached C client.

== License

Copyright 2009 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file. Portions copyright 2007-2009 TangentOrg, Brian Aker, licensed under the BSD license, and used with permission.

The public certificate for this gem is here[http://blog.evanweaver.com/files/evan_weaver-original-public_cert.pem]. 

If you use this software, please {make a donation}[http://blog.evanweaver.com/donate/], or {recommend Evan}[http://www.workingwithrails.com/person/7739-evan-weaver] at Working with Rails.

== Features

* clean API
* robust access to all memcached features
* multiple hashing modes, including consistent hashing
* ludicrous speed, including optional pipelined IO with no_reply

The <b>memcached</b> library wraps the pure-C libmemcached client via SWIG.

== Installation

You need Ruby 1.8.7 or Ruby 1.9.2. Other versions may work, but are not guaranteed. You also need the libsasl2-dev library, which should be provided through your system's package manager.

Install the gem:
  sudo gem install memcached --no-rdoc --no-ri
  
== Usage

Start a local networked memcached server:
  $ memcached -p 11211 &

Now, in Ruby, require the library and instantiate a Memcached object at a global level:

  require 'memcached'
  $cache = Memcached.new("localhost:11211")
  
Now you can set things and get things:
 
  value = 'hello'
  $cache.set 'test', value
  $cache.get 'test' #=> "hello"

You can set with an expiration timeout:

  value = 'hello'
  $cache.set 'test', value, 1
  sleep(2)
  $cache.get 'test' #=> raises Memcached::NotFound

You can get multiple values at once:

  value = 'hello'
  $cache.set 'test', value
  $cache.set 'test2', value
  $cache.get ['test', 'test2', 'missing'] 
    #=> {"test" => "hello", "test2" => "hello"}
  
You can set a counter and increment it:

  start = 1
  $cache.set 'counter', start, 0, false
  $cache.increment 'counter' #=> 2
  $cache.increment 'counter' #=> 3
  $cache.get('counter', false).to_i #=> 3

You can get some server stats:

  $cache.stats #=> {..., :bytes_written=>[62], :version=>["1.2.4"] ...}
  
Note that the API is not the same as that of <b>Ruby-MemCache</b> or <b>memcache-client</b>. In particular, <tt>nil</tt> is a valid record value. Memcached#get does not return <tt>nil</tt> on failure, rather it raises <b>Memcached::NotFound</b>. This is consistent with the behavior of memcached itself. For example:

  $cache.set 'test', nil
  $cache.get 'test' #=> nil
  $cache.delete 'test'
  $cache.get 'test' #=> raises Memcached::NotFound

== Legacy applications

There is a compatibility wrapper for legacy applications called Memcached::Rails. 

== Threading

<b>memcached</b> is threadsafe, but each thread requires its own Memcached instance. Create a global Memcached, and then call Memcached#clone each time you spawn a thread.

  thread = Thread.new do
    cache = $cache.clone
    # Perform operations on cache, not $cache
    cache.set 'example', 1
    cache.get 'example'
  end  

  # Join the thread so that exceptions don't get lost
  thread.join
  
== Benchmarks

<b>memcached</b>, correctly configured, is up to 60x faster than <b>memcache-client</b> or <b>dalli</b>. See BENCHMARKS[link:files/BENCHMARKS.html] for details.

== Reporting problems

The support forum is here[http://github.com/fauna/memcached/issues].

Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.

== Further resources

* {Memcached wiki}[http://www.socialtext.net/memcached/index.cgi]
* {Libmemcached homepage}[http://tangent.org/552/libmemcached.html]

memcached's People

Contributors

antifuchs avatar bierbaum avatar defunkt avatar e2 avatar evan avatar jberkel avatar packagethief avatar rgbenson avatar vandrijevik avatar wadey avatar yury avatar

Stargazers

 avatar

Watchers

 avatar

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.