A Ruby interface to the libmemcached C client
Перейти к файлу
Arthur Neves 5b93735f1d travis on latest 2.0 and 2.1 2016-02-06 18:06:28 -05:00
ext Fix warn on Config:: 2014-05-06 11:36:58 -04:00
lib Fix block in cas for Ruby 1.8.7 2014-05-06 14:39:33 +00:00
test remove bundle require, as we require the gems already 2016-02-06 17:54:55 -05:00
.gitignore Revert "Ignore Gemfile.lock" 2014-01-31 19:19:59 -05:00
.gitmodules Add the libmemcache HG repository and build it locally. 2008-11-14 11:50:16 +00:00
.ruby-version use 2.1.7 local 2016-02-06 17:54:23 -05:00
.travis.yml travis on latest 2.0 and 2.1 2016-02-06 18:06:28 -05:00
BENCHMARKS Update benchmarks 2014-01-30 23:49:51 -05:00
CHANGELOG Update changelog for 1.8.0 release 2014-05-07 14:55:47 -04:00
Gemfile Remove memcache, as it doesnt compile anymore on my machine 2016-02-06 18:04:55 -05:00
Gemfile.lock Remove memcache, as it doesnt compile anymore on my machine 2016-02-06 18:04:55 -05:00
LICENSE license 2008-01-20 09:16:17 +00:00
Manifest Gemspec 2014-05-07 12:01:35 -07:00
README.rdoc Update travis badge [skip ci] 2014-05-04 10:59:19 -04:00
Rakefile I guess we're testing 2.0 now. 2014-05-07 12:08:29 -07:00
TODO TODO 2012-09-27 22:08:08 -07:00
memcached.gemspec Update gemspec 2016-02-06 18:05:27 -05:00
memcached.pem Fix #143 2013-11-07 17:53:29 -08:00

README.rdoc

= memcached

An interface to the libmemcached C client.

{<img src="https://travis-ci.org/evan/memcached.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/evan/memcached]

== License

Copyright 2009-2013 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.

== Features

* clean API
* robust access to all memcached features
* SASL support for the binary protocol
* 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` and `gettext` libraries, 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. Note that you must initialize it with an integer, encoded as an unmarshalled ASCII string:

  start = 1
  $cache.set 'counter', start.to_s, 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

== Rails 3 and 4

Use {memcached_store gem}[https://github.com/Shopify/memcached_store] to integrate ActiveSupport cache store and memcached gem

== Pipelining

Pipelining updates is extremely effective in <b>memcached</b>, leading to more than 25x write throughput than the default settings. Use the following options to enable it:

  :no_block => true,
  :buffer_requests => true,
  :noreply => true,
  :binary_protocol => false

Currently #append, #prepend, #set, and #delete are pipelined. Note that when you perform a read, all pending writes are flushed to the servers.

== 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

== Legacy applications

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

== Benchmarks

<b>memcached</b>, correctly configured, is at least twice as fast as <b>memcache-client</b> and <b>dalli</b>. See link:BENCHMARKS for details.

== Reporting problems

The support forum is here[http://github.com/evan/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}[https://code.google.com/p/memcached/wiki/NewStart]
* {Libmemcached homepage}[libmemcached.org]