fastest jruby memcached client
Java Ruby
Latest commit 292d613 Dec 14, 2012 @flyerhzm flyerhzm Merge pull request #5 from phlipper/patch-1
add GitHub Flavored Markdown to README
Permalink
Failed to load latest commit information.
lib Bumping version to 0.5.1 Nov 10, 2012
spec use expect ... to instead of lambda ... should in rspec Nov 10, 2012
src/main/java ignore nil value in Memcached options Nov 10, 2012
target ignore nil value in Memcached options Nov 10, 2012
.gitignore
.travis.yml
CHANGELOG.md
Gemfile add rake to Gemfile Aug 20, 2012
MIT-LICENSE update README Jul 24, 2012
README.md add GitHub Flavored Markdown to README Dec 14, 2012
Rakefile add spec rake task for travis Aug 20, 2012
benchmark.rb memcached.quit in benchmark.rb Aug 20, 2012
jruby_memcached.gemspec update README Jul 24, 2012
pom.xml

README.md

jruby-memcached

A jruby memcached gem which is compatible with evan's memcached gem

Install

gem install jruby-memcached

Usage

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:

$cache.increment 'counter' #=> 1
$cache.increment 'counter' #=> 2
$cache.get('counter').to_i #=> 2

You can get some server stats:

$cache.stats #=> {..., :bytes_written=>[62], :version=>["1.2.4"] ...}

Rails

# config/environment.rb
config.cache_store = Memcached::Rails.new(:servers => ['127.0.0.1'])

Benchmarks

memcached.gem is the fastest memcached gem in MRI, jruby-memcached is the fastest memcached gem in JRuby. See benchmark