matsumotory / mruby-memcached

libmemcached bindings by mruby
Other
8 stars 4 forks source link

mruby-memcached Build Status

libmemcached bindings by mruby.

install by mrbgems

MRuby::Build.new do |conf|

    # ... (snip) ...

    conf.gem :git => 'https://github.com/matsumoto-r/mruby-memcached.git'
end

example

Get/Set

> m = Memcached.new "127.0.0.1:11211"
> m.set "hoge", "1"
 => 0
# defaule expire time is 0 sec(inifinity)
# m.set :foo, 10, 0
# if you want expire time 1000 sec,
# m.set :foo, 10, 1000
> m.set :foo, 10
 => 0
> m.get "hoge"
 => "1"
> m.get :hoge
 => "1"
> m.get "foo"
 => "10"
> m.close

Replicas

# m = Memcached.new "127.0.0.1:11211,127.0.0.1:11212,127.0.0.1:11213"
m = Memcached.new "127.0.0.1:11211"
m.server_add "127.0.0.1", 11212
m.server_add "127.0.0.1", 11213

m.behavior_set Memcached::MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
m.behavior_set Memcached::MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 2

m.set :hoge, "foo"
p m.get :hoge # => foo
m.flush_buffers

# exec the following memcat commands after flush_buffers

m.close

memcat

$ memcat --servers=127.0.0.1:11211 hoge
foo

$ memcat --servers=127.0.0.1:11212 hoge
foo

$ memcat --servers=127.0.0.1:11213 hoge
foo

License

under the MIT License: