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


Java MemcachedClient类代码示例

本文整理汇总了Java中net.rubyeye.xmemcached.MemcachedClient的典型用法代码示例。如果您正苦于以下问题:Java MemcachedClient类的具体用法?Java MemcachedClient怎么用?Java MemcachedClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MemcachedClient类属于net.rubyeye.xmemcached包,在下文中一共展示了MemcachedClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的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: MemcachedService

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public MemcachedService(Map<String, Object> srvCfg) {
	super.setResponseContentType(srvCfg);

	Map<String, String> statement = (Map<String, String>) srvCfg.get("statement");
	if (statement != null) {
		this.operate = statement.get("operate");

		String sourceName = (String) statement.get("source");
		if (StringUtils.isNotBlank(sourceName)) {
			DataSource ds = DataSourcePool.getDataSource(sourceName);
			if (ds != null) {
				Object session = ds.getSession();
				if (session instanceof MemcachedClient) {
					this.client = (MemcachedClient) session;
				}
			} else {
				throw new NullPointerException(String.format("Data source %s is not found", sourceName));
			}
		} else {
			throw new NullPointerException("Service source name is null");
		}
	} else {
		throw new NullPointerException("Service statement is null");
	}
}
 
开发者ID:PinaeOS,项目名称:pumbaa,代码行数:27,代码来源:MemcachedService.java

示例3: create

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
@Override
public CacheClient create(final List<InetSocketAddress> addrs, final CacheConfiguration conf) throws IOException {
    MemcacheClientWrapper clientWrapper = (MemcacheClientWrapper)super.create(addrs, conf);
    if (resolver==null) {
        return clientWrapper;
    }
    final MemcachedClient memcachedClient = (MemcachedClient) clientWrapper.getNativeClient();
    Object proxyInstance = Proxy.newProxyInstance( getClass().getClassLoader(), new Class[]{ MemcachedClient.class }, new InvocationHandler() {
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if(resolver.get().isPresent()) {
                String routingKey = resolver.get().get();
                memcachedClient.beginWithNamespace(routingKey);
                try {
                    return method.invoke(memcachedClient, args);
                } finally {
                    memcachedClient.endWithNamespace();
                }
            } else {
                throw new IllegalStateException("Unresolved routing key");
            }
        }
    });
    return new MemcacheClientWrapper((MemcachedClient) proxyInstance) ;
}
 
开发者ID:hekailiang,项目名称:cloud-config,代码行数:26,代码来源:RoutingMemcacheClientFactoryImpl.java

示例4: create

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的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

示例5: main

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的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

示例6: simpleClient

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的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

示例7: setApplicationContext

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
@SuppressWarnings("static-access")
@Override
public void setApplicationContext(ApplicationContext applicationContext)
		throws BeansException {
	this.applicationContext = applicationContext;
	this.client = getBean("memcachedClient", MemcachedClient.class);
}
 
开发者ID:wu560130911,项目名称:MultimediaDesktop,代码行数:8,代码来源:SpringContextHelper.java

示例8: MemCacheMapCache

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
public MemCacheMapCache(String name, MemcachedClient memcachedClient)
		throws CacheException {
	if (StringUtils.isBlank(name))
		throw new CacheException("缓存key不允许为空.");
	if (memcachedClient == null) {
		throw new CacheException("memcachedClient不允许为空.");
	}

	this.memcachedClient = memcachedClient;
	this.name = name;
}
 
开发者ID:wu560130911,项目名称:MultimediaDesktop,代码行数:12,代码来源:MemCacheMapCache.java

示例9: SyncLockMapCache

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
public SyncLockMapCache(String name, MemcachedClient memcachedClient,
		LocalZookeeperLock lock) throws CacheException {
	if (StringUtils.isBlank(name))
		throw new CacheException("缓存key不允许为空.");
	this.name = name;
	this.memcachedClient = memcachedClient;
	this.lock = lock;
}
 
开发者ID:wu560130911,项目名称:MultimediaDesktop,代码行数:9,代码来源:SyncLockMapCache.java

示例10: getMemcachedClient

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
/**
 * 获取Memcached连接
 * @return Memcached连接
 */
private MemcachedClient getMemcachedClient(){
    if(memcachedClient == null || memcachedClient.isShutdown()) {
        try {
            memcachedClient = memcachedClientBuilder.build();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return memcachedClient;
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:16,代码来源:MemcachedMap.java

示例11: containsKey

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
@Override
public boolean containsKey(Object key) {
    MemcachedClient memcachedClient = getMemcachedClient();
    try{
        return memcachedClient.get((String) key)!=null;
    }catch (Exception e){
        Logger.error(e);
        return false;
    }
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:11,代码来源:MemcachedMap.java

示例12: get

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
@Override
public String get(Object key) {
    MemcachedClient memcachedClient = getMemcachedClient();
    try{
        return memcachedClient.get((String) key);
    }catch (Exception e){
        Logger.error(e);
        return null;
    }
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:11,代码来源:MemcachedMap.java

示例13: put

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
@Override
public String put(String key, String value) {
    MemcachedClient memcachedClient = getMemcachedClient();
    try{
        if(memcachedClient.set(key, 0, value)) {
            return value;
        }else{
            return null;
        }
    }catch (Exception e){
        Logger.error(e);
        return null;
    }
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:15,代码来源:MemcachedMap.java

示例14: putWithNoReply

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
/**
 * 像 memcached 中放置对象数据
 *      不管数据存在不存在都会将目前设置的数据存储的 memcached,但不等待返回确认
 * @param key key 名称
 * @param value 数据
 * @param expire 超时时间
 * @return true: 成功, false:失败
 */
public Boolean putWithNoReply(String key, Object value, int expire) {
    MemcachedClient memcachedClient = null;
    try {
        memcachedClient = getMemcachedClient();
        memcachedClient.setWithNoReply(key, expire, value);
    } catch (Exception e) {
        Logger.error(e);
        return false;
    }
    return true;
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:20,代码来源:MemcachedMap.java

示例15: remove

import net.rubyeye.xmemcached.MemcachedClient; //导入依赖的package包/类
@Override
public String remove(Object key) {
    MemcachedClient memcachedClient = getMemcachedClient();
    try{
        String value = memcachedClient.get(key.toString());
        memcachedClient.delete(key.toString());
        return value;
    }catch (Exception e){
        Logger.error(e);
        return null;
    }
}
 
开发者ID:helyho,项目名称:Voovan,代码行数:13,代码来源:MemcachedMap.java


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