本文整理汇总了Java中net.rubyeye.xmemcached.MemcachedClientBuilder类的典型用法代码示例。如果您正苦于以下问题:Java MemcachedClientBuilder类的具体用法?Java MemcachedClientBuilder怎么用?Java MemcachedClientBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MemcachedClientBuilder类属于net.rubyeye.xmemcached包,在下文中一共展示了MemcachedClientBuilder类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String addr =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_HOST") : "localhost";
String port =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_PORT") : "11211";
String key = "count";
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(addr + ":" + port));
MemcachedClient client = builder.build();
long count = 0L;
try {
count = client.incr(key, 1L, 0L);
} catch (TimeoutException | InterruptedException | MemcachedException e) {
throw new ServletException("Memcache error", e);
}
resp.setContentType("text/plain");
resp.getWriter().print("Value is " + count + "\n");
}
示例2: create
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
/**
* Create a memcached client with params.
*
* @param hosts whitespace separated host or IP addresses and port numbers
* of the form "host:port host2:port hostN:portN"
* @param protocol opcional, BINARY or TEXT
* @param user opcional, user name o null
* @param pass opcional, password o null
* @param authMechanisms opcional, CRAM-MD5 and/or PLAIN
* @return memcached client
*/
public static MemcachedClient create(
String hosts,
CommandFactory protocol,
String user,
String pass,
String[] authMechanisms) {
MemcachedClient client = null;
try {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(hosts));
builder.setCommandFactory(protocol);
if (isNotNullOrEmpty(user)) {
builder.addAuthInfo(
AddrUtil.getAddresses(hosts).get(0),
new AuthInfo(
new PlainCallbackHandler(user, pass),
authMechanisms));
}
client = builder.build();
} catch (IOException ex) {
log.error("An error occurred when creating the MemcachedClient.", ex);
throw new PippoRuntimeException(ex);
}
return client;
}
示例3: main
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
public static void main(String[] args)
throws IOException, TimeoutException, InterruptedException, MemcachedException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder("localhost:11211");
MemcachedClient client = builder.build();
try {
ICacheEntrySerializer ces = DefaultCacheEntrySerializer.instance;
TestValue.Value v1 = new TestValue.Value();
CacheEntry ce = new CacheEntry("key", v1);
byte[] dataSet = ces.serialize(ce);
client.set("key", 0, dataSet);
System.out.println(dataSet.length);
byte[] dataGet = client.get("key");
System.out.println(dataGet.length);
} finally {
client.shutdown();
}
}
示例4: MemcachedService
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
public MemcachedService() {
MemcachedClientBuilder
builder =
new XMemcachedClientBuilder(
AddrUtil.getAddresses(ConfigUtil.get("memcached.url", "localhost:11211")));
// builder.setConnectionPoolSize(5);
try {
memcachedClient = builder.build();
} catch (IOException e) {
LOGGER.severe("Couldn't initialize memcached client", e);
}
expiry = ConfigUtil.getInt("cache.expiry", 84400);
}
示例5: simpleClient
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
private static MemcachedClient simpleClient() {
// AuthDescriptor ad = AuthDescriptor.typical("coca", "coca");
MemcachedClient mc = null;
try {
// mc = new MemcachedClient(new
// ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).build(),
// AddrUtil.getAddresses("localhost:11211"));
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("localhost:11211"));
mc = builder.build();
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
return mc;
}
示例6: createJedis
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
public static MemcachedClient createJedis(String hostport) throws IOException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(hostport));
MemcachedClient memcachedClient = null;
try {
memcachedClient = builder.build();
} catch (IOException e) {
throw e;
}
return memcachedClient;
}
示例7: init
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
@Override
public synchronized void init(Properties properties) throws IOException {
LOG.debug("init: KestrelClient initializing...");
this.initProperties = properties;
int connectionPoolSize = 1;
try {
connectionPoolSize = Integer.parseInt(properties.getProperty(PROP_KESTREL_CONNECTIONS));
} catch (Exception e) {
LOG.warn(PROP_KESTREL_CONNECTIONS+" undefined, using default of "+connectionPoolSize);
}
final List<InetSocketAddress> memcachedHosts = getMemcachedHosts(properties.getProperty(PROP_KESTREL_HOSTS));
final String hosts = properties.getProperty(PROP_KESTREL_HOSTS);
final MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(hosts));
builder.setCommandFactory(new KestrelCommandFactory());
builder.setConnectionPoolSize(connectionPoolSize);
client = builder.build();
client.setPrimitiveAsString(true);
final String reconnectIntervalString = properties.getProperty(PROP_RECONNECT_INTERVAL_IN_MINUTES);
if (reconnectIntervalString != null) {
reconnectIntervalMillis = 60 * 1000 * Long.parseLong(reconnectIntervalString);
}
lastConnect = System.currentTimeMillis();
LOG.info("init: KestrelClient fully initialized with hosts="+memcachedHosts+", reconnecting every "+(reconnectIntervalMillis/1000/60)+" minutes");
}
示例8: initMemcacheClient
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
/**
* 自己构建memcache客户端
*
* @return
* @throws IOException
*/
private static MemcachedClient initMemcacheClient() throws IOException {
// 构建client端的链接
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(ParaConstant.memcacheServerURI + ":"
+ ParaConstant.memcacheServerPort));
MemcachedClient memcachedClient = builder.build();
return memcachedClient;
}
示例9: addServer
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
@Test
public void addServer(){
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses("localhost:11111"));
try {
MemcachedClient memcachedClient = builder.build();
memcachedClient.addServer("localhost:11211");
} catch (Exception e) {
System.err.println("MemcachedClient operation fail");
e.printStackTrace();
}
}
示例10: init
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
public void init() throws IOException {
if(c!=null) stop();
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(hostList));
if(binaryConnection) {
builder.setCommandFactory(new BinaryCommandFactory());
}
builder.setConnectionPoolSize(poolSize);
c = builder.build();
}
示例11: setMem
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
/**
* 添加Memcache,保存用户信息到Memcache中
* @param key
* @param users
* @throws IOException
* @throws TimeoutException
* @throws InterruptedException
* @throws MemcachedException
*/
public void setMem(String key, UserInfoBean userInfoBean) throws IOException,
TimeoutException, InterruptedException, MemcachedException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
"127.0.0.1:11211");
MemcachedClient client = builder.build();
client.set(key, 0, userInfoBean);
}
示例12: getMem
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
/**
* 验证Memcache,从Memcache中查询数据
* @param value
* @return
* @throws IOException
* @throws TimeoutException
* @throws InterruptedException
* @throws MemcachedException
*/
public Object getMem(String value) throws IOException, TimeoutException,
InterruptedException, MemcachedException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
"127.0.0.1:11211");
MemcachedClient client = builder.build();
return client.get(value);
}
示例13: newMemcachedClient
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
/**
* Creates a new {@link MemcachedClient}, with specified connection timeout
* and connection pool size.
*
* @param hostsAndPorts
* Memcached' hosts and ports scheme (format
* {@code host1:port1,host2:port2}).
* @param connTimeoutMs
* @param connPoolSize
* @return
* @throws IOException
*/
public static MemcachedClient newMemcachedClient(String hostsAndPorts, long connTimeoutMs,
int connPoolSize) throws IOException {
hostsAndPorts = StringUtils.join(hostsAndPorts.split("[\\s,;]+"), ' ');
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(hostsAndPorts));
builder.setConnectTimeout(connTimeoutMs);
builder.setConnectionPoolSize(connPoolSize);
return builder.build();
}
示例14: MemcachedMap
import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
/**
* 构造函数
* @param memcachedClientBuilder Memcached 连接池对象
*/
public MemcachedMap(MemcachedClientBuilder memcachedClientBuilder){
this.memcachedClientBuilder = memcachedClientBuilder;
}