使用的memcache客户端与红宝石红宝石、客户端、memcache

2023-09-11 10:15:01 作者:浮华乱世ミ谁许谁一生繁华

我试图使用的memcache客户端连接创建亚马逊elastiCache集群终端。 但我得到的错误

 的memcache :: MemCacheError:未连接到服务器(testcachecluster.u098ed.cfg.us
e1.cache.amazonaws.com:11211 DEAD(超时::错误:执行到期),将RETR
Ÿ在2013年6月21日11点34分15秒0530)
        从C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache客户端-1.8.5 / lib中/ memcache.rb:863:在'with_socket_management
        从C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache客户端-1.8.5 / lib中/ memcache.rb:370:在'块集
        从C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache客户端-1.8.5 / lib中/ memcache.rb:886:在'with_server
        从C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/me
mcache客户端-1.8.5 / lib中/ memcache.rb:361:在'设置'
        从(IRB):5
        从C:/ProgramData/RailsInstaller/Ruby1.9.3/bin/irb:12:在`<主>
 

但亚马逊elastiCache集群端点使用本地主机instread我得到正确的。

  IRB(主):006:0> M = MemCache.new('本地主机:11211)
=> < MEMCACHE:1的服务器,NS:无,RO:假>
IRB(主):007:0> m.set'ABC','某某'
=> 存储\ r \ N
IRB(主):008:0> m.get'ABC'
=> XYZ
IRB(主):009:0>
 

解决方案

好了,对我来说,问题是安全组。您只能从具有列出的Elasticache安全组一个安全组的EC2实例访问Elasticache节点。

所以对我来说,我的EC2实例具有网络的安全组。在elasticache,然后我说网络到默认elasticache安全组。

滚动的天空2 红宝石获得方法分享 如何获得红宝石

下面进一步解释:的http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheSecurityGroup.html

另外,尝试使用这两种宝石的:

https://github.com/mperham/dalli

https://github.com/ktheory/dalli-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>'

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

解决方案

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.

So for me, my ec2 instance has a security group of "web". In elasticache, I then added "web" to the "default" elasticache security group.

Further explanation here: http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheSecurityGroup.html

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.

 
精彩推荐
图片推荐