答案 0 :(得分:0)
我遇到了同样的问题。我发现这个链接显示了使用PHP创建的客户端。我能够将其作为创建Java客户端的基础:http://blog.shupp.org/2011/05/07/getting-started-with-kestrel-from-a-php-application/
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import net.spy.memcached.MemcachedClient;
public class KestrelClient {
private MemcachedClient client = null;
private String kestrelHost = null;
private int kestrelPort = -1;
public KestrelClient(final String kestrelHost, final int kestrelPort)
{
this.kestrelHost = kestrelHost;
this.kestrelPort = kestrelPort;
try
{
this.client = new MemcachedClient(new InetSocketAddress(this.kestrelHost, this.kestrelPort));
}
catch (IOException e)
{
e.printStackTrace();
}
}
public boolean set(final String queueName, final int expiration, final Object data)
{
Future<Boolean> setFuture = this.client.set(queueName, expiration, data);
try
{
return setFuture.get().booleanValue();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
catch (ExecutionException e)
{
e.printStackTrace();
}
return false;
}
public Object reliableRead(final String queueName, final int timeout)
{
Object object = this.client.get(queueName + "/close/open/t=" + timeout);
closeReliableRead(queueName);
return object;
}
public void closeReliableRead(final String queueName)
{
this.client.get(queueName + "/close");
}
public void abortReliableRead(final String queueName)
{
this.client.get(queueName + "/abort");
}
}
它并不完美,但它应该让你开始。 (对spymemcached的依赖。)
祝你好运!答案 1 :(得分:0)
我遇到了同样的问题。我最初使用xmemcached客户端,但后来发现使用简单的包装器更容易使用它。这个包装器变成了jestrel,这是在Apache许可下提供的:
https://github.com/cobbzilla/jestrel
我设计了jestrel API,非常简单。它已在生产环境中经过测试并表现良好。试一试,让我知道你的想法。