Memcached 学习笔记(二)——ruby调用ruby
上一节咱们讲述了怎样安装memcached及memcached经常使用命令。这一节咱们将经过ruby来调用memcached相关操做。memcached
第一步,安装ruby.此操做很是简单,直接yum install ruby便可。学习
第二步,安装rubygems,一样,yum install rubygems.测试
第三步,安装程序库memcache-client,运行命令:ui
gem install memcache-client
第四步,运行ruby测试程序:spa
$KCODE='u' require "rubygems" require "memcache" server=['localhost:11211'] option={} cache=MemCache.new(server,option) cache['key1']=123 cache['key2']="ABCDE" cache['key3']=%w(hoge fuga) cache['key4']={:foo=>1,:bar=>"a"} p cache['key1'] p cache['key2'] p cache['key3'] p cache['key4']
结果以下图:code
第五步,经过telnet查看是否已经存在内存中:server
第六步,在ruby程序中设置过时时间内存
[root@localhost ~]# ruby require "rubygems" require "memcache" cache=MemCache.new(['localhost:11211 ']) cache.set('key','value',10) p cache['key'] sleep 11 p cache['key'] "value" nil