2

我用jelastic的memcached尝试了一个简单的测试,总是得到异常“连接被拒绝”......但URL是正确的。是不是有些加

    MemcachedClient c = new MemcachedClient(
            new InetSocketAddress("memcached-myexample.jelastic.dogado.eu", 11211));

    c.set("someKey", 3600, user);

    User cachedUser = (User) c.get("someKey");

这是一个例外:

2014-01-02 00:07:41.820 INFO net.spy.memcached.MemcachedConnection:  Added {QA sa=memcached-myexample.jelastic.dogado.eu/92.51.168.106:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2014-01-02 00:07:41.833 WARN net.spy.memcached.MemcachedConnection:  Could not redistribute to another node, retrying primary node for someKey.
2014-01-02 00:07:41.835 WARN net.spy.memcached.MemcachedConnection:  Could not redistribute to another node, retrying primary node for someKey.
2014-01-02 00:07:41.858 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@2dc1482f
2014-01-02 00:07:41.859 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=memcached-myexample.jelastic.dogado.eu/92.51.168.106:11211, #Rops=0, #Wops=2, #iq=0, topRop=null, topWop=Cmd: set Key: someKey Flags: 1 Exp: 3600 Data Length: 149, toWrite=0, interested=0}
java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:735)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:629)
    at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:409)
    at net.spy.memcached.MemcachedConnection.run(MemcachedConnection.java:1334)
4

4 回答 4

0

首先添加int portNum = 11211;,然后重试。

int portNum = 11211;
MemcachedClient c = new MemcachedClient(
new InetSocketAddress("memcached-myexample.jelastic.dogado.eu", portNum));

// Store a value (async) for one hour
c.set("someKey", 3600, someObject);
// Retrieve a value (synchronously).
Object myObject=c.get("someKey");
于 2014-01-03T13:44:43.407 回答
0

我会尝试 telnet 到您的 memcached 集群以排除防火墙问题。您可以使用以下命令执行此操作。

telnet memcached-myexample.jelastic.dogado.eu 11211

如果这不起作用,则说明您有网络问题。如果是这种情况,我会首先检查您是否有防火墙。

于 2014-01-03T01:07:01.577 回答
0

谢谢,但错误出在提供商的防火墙规则上。所以不是我的失败。

于 2014-01-03T19:36:43.573 回答
0

检查 /etc/memcached.conf 文件并更新您要从中访问缓存的服务器 IP 地址。

于 2016-06-14T12:05:32.003 回答