本文整理了Java中net.spy.memcached.MemcachedClient.add()
方法的一些代码示例,展示了MemcachedClient.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MemcachedClient.add()
方法的具体详情如下:
包路径:net.spy.memcached.MemcachedClient
类名称:MemcachedClient
方法名:add
[英]Add an object to the cache (using the default transcoder) iff it does not exist already.
The exp
value is passed along to memcached exactly as given, and will be processed per the memcached protocol specification:
Note that the return will be false any time a mutation has not occurred.
The actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60602430 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.
[中]如果对象不存在,则将其添加到缓存(使用默认转码器)。exp
值完全按照给定值传递给memcached,并将按照memcached协议规范进行处理:
请注意,只要没有发生突变,返回值就会为假。
发送的实际值可以是Unix时间(自1970年1月1日起的秒数,作为32位值),也可以是从当前时间开始的秒数。在后一种情况下,该秒数不得超过60602430(30天内的秒数);如果客户端发送的数字大于此,服务器将认为它是真正的UNIX时间值,而不是当前时间的偏移量。
代码示例来源:origin: ninjaframework/ninja
public void add(String key, Object value, int expiration) {
client.add(key, expiration, value, tc);
}
代码示例来源:origin: ninjaframework/ninja
public boolean safeAdd(String key, Object value, int expiration) {
Future<Boolean> future = client.add(key, expiration, value, tc);
try {
return future.get(1, TimeUnit.SECONDS);
} catch (Exception e) {
future.cancel(false);
}
return false;
}
代码示例来源:origin: apache/hbase
@Override
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf) {
if (buf instanceof HFileBlock) {
client.add(cacheKey.toString(), MAX_SIZE, (HFileBlock) buf, tc);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("MemcachedBlockCache can not cache Cacheable's of type "
+ buf.getClass().toString());
}
}
}
代码示例来源:origin: aol/micro-server
@Override
public boolean add(final String key, int exp, final Object value) {
log.trace("Memcached add operation on key '{}', with value:{}", key, value);
boolean success = false;
int tryCount = 0;
do {
try {
if (tryCount > 0) {
Thread.sleep(retryAfterSec * 1000);
log.warn("retrying operation #{}", tryCount);
}
tryCount++;
success = memcachedClient.add(key, exp, value)
.get();
} catch (final Exception e) {
log.warn("memcache set: {}", e.getMessage());
}
} while (!success && tryCount < maxTry);
if (!success) {
log.error("Failed to add key to Elasticache {}", key);
}
if (success && tryCount > 1) {
log.info("Connection restored OK to Elasticache cluster");
}
available = success;
return success;
}
代码示例来源:origin: brianfrankcooper/YCSB
@Override
public Status insert(
String table, String key, Map<String, ByteIterator> values) {
key = createQualifiedKey(table, key);
try {
OperationFuture<Boolean> future =
memcachedClient().add(key, objectExpirationTime, toJson(values));
return getReturnCode(future);
} catch (Exception e) {
logger.error("Error inserting value", e);
return Status.ERROR;
}
}
代码示例来源:origin: magro/memcached-session-manager
@Override
public Future<Boolean> add(String key, int exp, byte[] o) {
return _memcached.add(key, exp, o, ByteArrayTranscoder.INSTANCE);
}
代码示例来源:origin: aol/micro-server
@Before
public void setup() {
memcachedClient = mock(MemcachedClient.class);
stub(memcachedClient.get("key1")).toReturn("value1");
stub(memcachedClient.get("key2")).toReturn("value2");
OperationFuture<Boolean> mockedFuture = mock(OperationFuture.class);
stub(memcachedClient.add("keyAdd", 3600, "valueadd")).toReturn(mockedFuture);
}
代码示例来源:origin: magro/memcached-session-manager
when( futureMock.get() ).thenReturn( Boolean.FALSE );
when( futureMock.get( anyInt(), any( TimeUnit.class ) ) ).thenReturn( Boolean.FALSE );
when( _memcachedMock.add( any( String.class ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( futureMock );
verify( _memcachedMock, times( 1 ) ).add( eq( sessionId ), anyInt(), any(), any( Transcoder.class ) );
verify( _memcachedMock, times( 1 ) ).add( eq( backupSessionKey ), anyInt(), any(), any( Transcoder.class ) );
代码示例来源:origin: magro/memcached-session-manager
when(addResultMock.get()).thenReturn(true);
when(addResultMock.get(anyLong(), any(TimeUnit.class))).thenReturn(true);
when(_memcachedMock.add(anyString(), anyInt(), any(), any(Transcoder.class))).thenReturn(addResultMock);
代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play
@Override
public boolean safeAdd(String key, Object value, int expiration) {
Future<Boolean> future = client.add(key, expiration, value, tc);
try {
return future.get(1, TimeUnit.SECONDS);
} catch (Exception e) {
future.cancel(false);
}
return false;
}
代码示例来源:origin: io.snappydata/gemfire-junit
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;
}
代码示例来源:origin: com.aliyun.hbase/alihbase-external-blockcache
@Override
public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf) {
if (buf instanceof HFileBlock) {
client.add(cacheKey.toString(), MAX_SIZE, (HFileBlock) buf, tc);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("MemcachedBlockCache can not cache Cacheable's of type "
+ buf.getClass().toString());
}
}
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testAdd() throws Exception {
MemcachedClient client = bootstrapClient();
Future<Boolean> f = client.add("key", 10, "newVal");
assertFalse(f.get());
}
代码示例来源:origin: io.snappydata/gemfire-junit
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"));
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testStats() throws Exception {
MemcachedClient client = bootstrapClient();
Map stats = client.getStats();
logger.info("stats:"+stats+" val:"+stats.values().toArray()[0]);
assertEquals(1, stats.size());
assertTrue(((Map)stats.values().toArray()[0]).isEmpty());
assertTrue(client.add("keystats", 1, "stats").get());
}
代码示例来源:origin: io.snappydata/gemfire-junit
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"));
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testDecr() throws Exception {
MemcachedClient client = bootstrapClient();
client.add("decrkey", 10, 99).get();
assertEquals(95, client.decr("decrkey", 4));
assertEquals(94, client.decr("decrkey", 1));
assertEquals(-1, client.decr("decrkey1", 77));
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testIncr() throws Exception {
MemcachedClient client = bootstrapClient();
client.add("incrkey", 10, 99).get();
assertEquals(104, client.incr("incrkey", 5));
assertEquals(105, client.incr("incrkey", 1));
assertEquals(-1, client.incr("inckey1", 10));
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testCas() throws Exception {
MemcachedClient client = bootstrapClient();
client.add("caskey", 10, "casValue").get();
CASValue<Object> val = client.gets("caskey");
assertEquals("casValue", val.getValue());
CASResponse r = client.cas("caskey", val.getCas(), "newValue");
assertEquals(CASResponse.OK, r);
r = client.cas("caskey", val.getCas(), "newValue2");
assertEquals(CASResponse.EXISTS, r);
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testGets() throws Exception {
MemcachedClient client = bootstrapClient();
client.add("getskey", 10, "casValue").get();
CASValue<Object> val = client.gets("getskey");
long oldCas = val.getCas();
assertEquals("casValue", val.getValue());
client.replace("getskey", 10, "myNewVal").get();
val = client.gets("getskey");
assertEquals(oldCas + 1, val.getCas());
assertEquals("myNewVal", val.getValue());
}
内容来源于网络,如有侵权,请联系作者删除!