本文整理汇总了Java中net.spy.memcached.MemcachedClient.add方法的典型用法代码示例。如果您正苦于以下问题:Java MemcachedClient.add方法的具体用法?Java MemcachedClient.add怎么用?Java MemcachedClient.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.spy.memcached.MemcachedClient
的用法示例。
在下文中一共展示了MemcachedClient.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGemFireProperty
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void testGemFireProperty() throws Exception {
Properties props = new Properties();
final int port = AvailablePortHelper.getRandomAvailableTCPPort();
props.setProperty("memcached-port", port+"");
CacheFactory cf = new CacheFactory(props);
Cache cache = cf.create();
MemcachedClient client = new MemcachedClient(
new InetSocketAddress(SocketCreator.getLocalHost(), port));
Future<Boolean> f = client.add("key", 10, "myStringValue");
assertTrue(f.get());
Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
assertTrue(f1.get());
assertEquals("myStringValue", client.get("key"));
assertEquals("myStringValue1", client.get("key1"));
assertNull(client.get("nonExistentkey"));
cache.close();
}
示例2: main
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException
{
final MemcachedClient c = new MemcachedClient(new InetSocketAddress("localhost", 11211));
Object o = c.get(KEY);
System.err.println("1. get: " + o);
OperationFuture<Boolean> add = c.add(KEY, 50000, "1");
add.addListener(new OperationCompletionListener()
{
@Override
public void onComplete(OperationFuture<?> operationFuture) throws Exception
{
Object o2 = c.get(KEY);
System.err.println("2. get: " + o2);
c.delete(KEY);
Object o3 = c.get(KEY);
System.err.println("3. get: " + o3);
c.shutdown();
}
});
}
示例3: testGetPutDomainObject
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void testGetPutDomainObject() throws Exception {
MemcachedClient client = new MemcachedClient(
new InetSocketAddress(SocketCreator.getLocalHost(), PORT));
Customer c = new Customer("name0", "addr0");
Customer c1 = new Customer("name1", "addr1");
Future<Boolean> f = client.add("keyObj", 10, c);
assertTrue(f.get());
Future<Boolean> f1 = client.add("key1", 10, c1);
assertTrue(f1.get());
assertEquals(c, client.get("keyObj"));
assertEquals(c1, client.get("key1"));
assertNull(client.get("nonExistentkey"));
}
示例4: testPutGet
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void testPutGet() throws Exception {
MemcachedClient client = createMemcachedClient();
Future<Boolean> f = client.add("key", 10, "myStringValue");
assertTrue(f.get());
Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
assertTrue(f1.get());
assertEquals("myStringValue", client.get("key"));
assertEquals("myStringValue1", client.get("key1"));
assertNull(client.get("nonExistentkey"));
// zero exp
f = client.add("Hello", 0, "World");
Thread.sleep(1100);
assertEquals("World", client.get("Hello"));
}
示例5: testMultiGet
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void testMultiGet() throws Exception {
MemcachedClient client = bootstrapClient();
Map<String, Object> val = client.getBulk("key", "key1");
assertEquals(2, val.size());
assertEquals("myStringValue", val.get("key"));
assertEquals("myStringValue1", val.get("key1"));
client.add("Hello", 0, "World");
Thread.sleep(1100);
assertEquals("World", client.get("Hello"));
}
示例6: bootstrapClient
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
private MemcachedClient bootstrapClient() throws IOException,
UnknownHostException, InterruptedException, ExecutionException {
MemcachedClient client = createMemcachedClient();
Future<Boolean> f = client.add("key", 10, "myStringValue");
f.get();
Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
f1.get();
return client;
}
示例7: testAdd
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void testAdd() throws Exception {
MemcachedClient client = bootstrapClient();
Future<Boolean> f = client.add("key", 10, "newVal");
assertFalse(f.get());
}
示例8: testLongExpiration
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void testLongExpiration() throws Exception {
MemcachedClient client = bootstrapClient();
client.add("newKey", (int)System.currentTimeMillis() - 60 *1000, "newValue");
Thread.sleep(15 *1000);
assertEquals("newValue", client.get("newKey"));
}