使用带有 ruby 的内存缓存客户端 [英] Using memcache client with ruby
问题描述
我正在尝试使用 memcache-client 连接创建的 amazon elastiCache 集群端点.但是我收到错误
Am trying to connect created amazon elastiCache cluster endpoint using memcache-client. But am getting the error
MemCache::MemCacheError: No connection to server (testcachecluster.u098ed.cfg.us
e1.cache.amazonaws.com:11211 DEAD (Timeout::Error: execution expired), will retr
y at 2013-06-21 11:34:15 +0530)
from C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache-client-1.8.5/lib/memcache.rb:863:in `with_socket_management'
from C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache-client-1.8.5/lib/memcache.rb:370:in `block in set'
from C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache-client-1.8.5/lib/memcache.rb:886:in `with_server'
from C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache-client-1.8.5/lib/memcache.rb:361:in `set'
from (irb):5
from C:/ProgramData/RailsInstaller/Ruby1.9.3/bin/irb:12:in `<main>'
但是使用 localhost instread of amazon elastiCache 集群端点是正确的.
But using localhost instread of amazon elastiCache cluster endpoint am getting correctly.
irb(main):006:0> m = MemCache.new('localhost:11211')
=> <MemCache: 1 servers, ns: nil, ro: false>
irb(main):007:0> m.set 'abc', 'xyz'
=> "STORED
"
irb(main):008:0> m.get 'abc'
=> "xyz"
irb(main):009:0>
推荐答案
好吧,对我来说,问题出在安全组上.您只能从具有在 Elasticache 安全组中列出的安全组的 ec2 实例访问 Elasticache 节点.
Ok, for me, the problem was the security groups. You can only access Elasticache nodes from ec2 instances that have a security group that is listed in the Elasticache security group.
所以对我来说,我的 ec2 实例有一个web"安全组.在 elasticache 中,我然后将web"添加到默认"elasticache 安全组中.
So for me, my ec2 instance has a security group of "web". In elasticache, I then added "web" to the "default" elasticache security group.
此处的进一步解释:http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheSecurityGroup.html
另外,尝试使用这两个 gem 中的任何一个:
Also, try using either of these two gems:
https://github.com/mperham/dalli
https://github.com/ktheory/dalli-elasticache
我正在使用后者并且效果很好,因为它使用节点的自动发现.
I'm using the latter and it works great because it uses autodiscovery of the nodes.
这篇关于使用带有 ruby 的内存缓存客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!