7

我一直无法在Amazon Cloud上找到关于Memcached的良好教程,我对这整个缓存事情很陌生。 我试图通过亚马逊的ElastiCache服务和一个间谍缓存客户端使用memcached来实际进行memcached调用。在Java中设置Amazon ElastiCache w/spymemcached

下面是我在做什么用Java现在:

try { 
     ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder(); 
     MemcachedClient memcachedClient = new MemcachedClient(
       connectionFactoryBuilder.build(), 
       AddrUtil.getAddresses("<beginning of cache node end point grabbed from AWS Console>.cache.amazonaws.com:11211")); 
     memcachedClient.set("test", 12, new Integer(12)); 
     System.out.println(memcachedClient.get("test")); 
    } catch (IOException ioException) { 
     ioException.printStackTrace(); 
    } 

,我得到的错误,当我尝试是这样的:

java.net.ConnectException: Connection refused 
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) 
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567) 
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:414) 
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:278) 
at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:1981) 
2012-02-01 19:25:35.415 WARN net.spy.memcached.MemcachedConnection: Closing, and  reopening {QA sa=<node endpoint>.cache.amazonaws.com/184.73.64.56:11211, #Rops=0, #Wops=2, #iq=0, topRop=null, [email protected]e, toWrite=0, interested=0}, attempt 1. 
net.spy.memcached.OperationTimeoutException: Timeout waiting for value 
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1142) 
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1157) 
at com.amazon.imaging.demo.SQSQueueManager.requeue(SQSQueueManager.java:117) 
at com.amazon.imaging.demo.SQSQueueManager.requeue(SQSQueueManager.java:88) 
at com.amazon.imaging.demo.DemoUI$4.run(DemoUI.java:368) 
at com.amazon.imaging.demo.DemoUI.main(DemoUI.java:391) 
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: <node endpoint>.cache.amazonaws.com/184.73.64.56:11211 
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:65) 
at net.spy.memcached.internal.GetFuture.get(GetFuture.java:37) 
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1135) 
... 5 more 

任何人得到这个任何想法或经验? 谢谢!

回答

2

你在哪里执行此操作?在EC2实例中或从外部网络中。请记住,ElastiCache服务器受限于访问ElastiCAche实例的安全组。因此,请检出安全组和允许您连接到Memcached服务器的其他配置。据我所知,ElastiCache不能从外部AWS边界访问

其余代码看起来不错,并且cConsider使用像Spring这样的框架来处理memcache客户端对象实例化和相关配置。