【问题标题】:Using memcache client with ruby将 memcache 客户端与 ruby​​ 一起使用
【发布时间】:2013-06-18 05:03:28
【问题描述】:

我正在尝试使用 memcache-client 连接创建的 amazon elastiCache 集群端点。 但是我得到了错误

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

但是使用 amazon elastiCache 集群端点的 localhost instread 是正确的。

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\r\n"
irb(main):008:0> m.get 'abc'
=> "xyz"
irb(main):009:0>

【问题讨论】:

  • 你解决了吗?我有类似的问题。
  • 不,我没有解决问题!我使用了 memcached 和 memcache-client 而不是 memcache 。但是发生了同样的错误
  • 如果你有任何解决方案也请帮助我

标签: ruby amazon-web-services memcached amazon-elasticache


【解决方案1】:

好的,对我来说,问题在于安全组。您只能从具有 Elasticache 安全组中列出的安全组的 ec2 实例访问 Elasticache 节点。

所以对我来说,我的 ec2 实例有一个“web”安全组。在 elasticache 中,我随后将“web”添加到“默认”elasticache 安全组中。

这里进一步解释:http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheSecurityGroup.html

另外,请尝试使用以下两种 gem 中的任何一种:

https://github.com/mperham/dalli

https://github.com/ktheory/dalli-elasticache

我使用的是后者,因为它使用节点的自动发现,所以效果很好。

【讨论】:

  • 你能告诉我们在 config/initializers/session_store.rb 和 config/environments/production.rb 中使用什么代码来处理 dalli-elasticache 吗?
  • dalli-elasticache 有效。我刚刚检查了 Rails 4.2.5
猜你喜欢
  • 1970-01-01
  • 2012-10-16
  • 2014-01-03
  • 1970-01-01
  • 2010-12-24
  • 2021-01-21
  • 1970-01-01
  • 2014-01-14
  • 2013-01-19
相关资源
最近更新 更多