当前位置: 首页>>代码示例>>Java>>正文


Java MemcachedClientBuilder类代码示例

本文整理汇总了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");
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:23,代码来源:MemcacheServlet.java

示例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;
}
 
开发者ID:decebals,项目名称:pippo,代码行数:36,代码来源:XmemcachedFactory.java

示例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();
    }
}
 
开发者ID:DDTH,项目名称:ddth-cache-adapter,代码行数:19,代码来源:QndXMemcachedBinary.java

示例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);
  }
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:14,代码来源:MemcachedService.java

示例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;
}
 
开发者ID:dzh,项目名称:coca,代码行数:15,代码来源:CaMemcached.java

示例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;
}
 
开发者ID:whyDK37,项目名称:pinenut,代码行数:14,代码来源:MCUtil.java

示例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");
}
 
开发者ID:cobbzilla,项目名称:jestrel,代码行数:30,代码来源:KestrelClient.java

示例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;
}
 
开发者ID:suhuanzheng7784877,项目名称:ParallelExecute,代码行数:15,代码来源:ProgressContextMemcache.java

示例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();
	}
}
 
开发者ID:suhuanzheng7784877,项目名称:ParallelExecute,代码行数:16,代码来源:MemcacheTest.java

示例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();
}
 
开发者ID:QuickServerLab,项目名称:QuickCached,代码行数:12,代码来源:XMemcachedImpl.java

示例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);
}
 
开发者ID:developerfanyl,项目名称:online-book-shopping,代码行数:17,代码来源:LandAndRegistrationBll.java

示例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);
}
 
开发者ID:developerfanyl,项目名称:online-book-shopping,代码行数:17,代码来源:LandAndRegistrationBll.java

示例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();
}
 
开发者ID:DDTH,项目名称:ddth-cache-adapter,代码行数:22,代码来源:XMemcachedCacheFactory.java

示例14: MemcachedMap

import net.rubyeye.xmemcached.MemcachedClientBuilder; //导入依赖的package包/类
/**
 * 构造函数
 * @param memcachedClientBuilder Memcached 连接池对象
 */
public MemcachedMap(MemcachedClientBuilder memcachedClientBuilder){
    this.memcachedClientBuilder = memcachedClientBuilder;
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:8,代码来源:MemcachedMap.java


注:本文中的net.rubyeye.xmemcached.MemcachedClientBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。