读书人

Kestrel行列使用示例

发布时间: 2013-04-02 12:35:26 作者: rapoo

Kestrel队列使用示例
package com.wujintao.kestrel;import java.io.IOException;import java.util.concurrent.TimeoutException;import org.junit.BeforeClass;import org.junit.Test;import net.rubyeye.xmemcached.MemcachedClient;import net.rubyeye.xmemcached.MemcachedClientBuilder;import net.rubyeye.xmemcached.XMemcachedClientBuilder;import net.rubyeye.xmemcached.command.KestrelCommandFactory;import net.rubyeye.xmemcached.exception.MemcachedException;import net.rubyeye.xmemcached.utils.AddrUtil;public class TestCase {private static MemcachedClient memcachedClient;private String ketrelQueueName = "abc";@BeforeClasspublic static void init() {MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("localhost:22133"));builder.setCommandFactory(new KestrelCommandFactory());try {memcachedClient = builder.build();} catch (IOException e) {e.printStackTrace();}memcachedClient.setOptimizeGet(false);memcachedClient.setConnectTimeout(60000);}@Testpublic void testPutValue() throws TimeoutException, InterruptedException, MemcachedException{boolean flag = memcachedClient.set(ketrelQueueName, 0, "1:111");System.out.println(flag);}@Testpublic void testGetValue() throws TimeoutException, InterruptedException, MemcachedException{Object str = memcachedClient.get(ketrelQueueName);System.out.println(str);}}

?

读书人网 >编程

热点推荐