net.spy.memcached.MemcachedClient.replace()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中net.spy.memcached.MemcachedClient.replace()方法的一些代码示例,展示了MemcachedClient.replace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MemcachedClient.replace()方法的具体详情如下:
包路径:net.spy.memcached.MemcachedClient
类名称:MemcachedClient
方法名:replace

MemcachedClient.replace介绍

[英]Replace an object with the given value (transcoded with the default transcoder) iff there is already a value for the given key.

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位值),也可以是从当前时间开始的秒数。在后一种情况下,该秒数不得超过60
602430(30天内的秒数);如果客户端发送的数字大于此,服务器将认为它是真正的UNIX时间值,而不是当前时间的偏移量。

代码示例

代码示例来源:origin: ninjaframework/ninja

public void replace(String key, Object value, int expiration) {
  client.replace(key, expiration, value, tc);
}

代码示例来源:origin: ninjaframework/ninja

public boolean safeReplace(String key, Object value, int expiration) {
  Future<Boolean> future = client.replace(key, expiration, value, tc);
  try {
    return future.get(1, TimeUnit.SECONDS);
  } catch (Exception e) {
    future.cancel(false);
  }
  return false;
}

代码示例来源:origin: jooby-project/jooby

@Override
public void delete(final String id) {
 String key = key(id);
 memcached.replace(key, 1, new HashMap<>());
}

代码示例来源:origin: brianfrankcooper/YCSB

@Override
public Status update(
  String table, String key, Map<String, ByteIterator> values) {
 key = createQualifiedKey(table, key);
 try {
  OperationFuture<Boolean> future =
    memcachedClient().replace(key, objectExpirationTime, toJson(values));
  return getReturnCode(future);
 } catch (Exception e) {
  logger.error("Error updating value with key: " + key, e);
  return Status.ERROR;
 }
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play

@Override
public void replace(String key, Object value, int expiration) {
  client.replace(key, expiration, value, tc);
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play

@Override
public boolean safeReplace(String key, Object value, int expiration) {
  Future<Boolean> future = client.replace(key, expiration, value, tc);
  try {
    return future.get(1, TimeUnit.SECONDS);
  } catch (Exception e) {
    future.cancel(false);
  }
  return false;
}

代码示例来源:origin: org.jooby/jooby-spymemcached

@Override
public void delete(final String id) {
 String key = key(id);
 memcached.replace(key, 1, new HashMap<>());
}

代码示例来源:origin: io.snappydata/gemfire-junit

public void testReplace() throws Exception {
 MemcachedClient client = bootstrapClient();
 Future<Boolean> b = client.replace("key", 10, "newVal");
 assertTrue(b.get());
 b = client.replace("nonExistentkey", 10, "val");
 assertFalse(b.get());
 b = client.replace("key", 10, "myStringValue");
 assertTrue(b.get());
}

代码示例来源:origin: aurorafeint/jruby-memcached

while (true) {
  try {
    Boolean result = (Boolean) client.replace(key, expiry, value, transcoder).get();
    if (!result) {
      throw Error.newNotStored(ruby, "not stored");

代码示例来源:origin: org.opensaml/opensaml-storage-impl

/** {@inheritDoc} */
@Override
public boolean update(@Nonnull @NotEmpty final String context,
           @Nonnull @NotEmpty final String key,
           @Nonnull @NotEmpty final String value,
           @Nullable @Positive final Long expiration) throws IOException {
  Constraint.isNotNull(StringSupport.trimOrNull(context), "Context cannot be null or empty");
  Constraint.isNotNull(StringSupport.trimOrNull(key), "Key cannot be null or empty");
  Constraint.isNotNull(StringSupport.trimOrNull(value), "Value cannot be null or empty");
  final MemcachedStorageRecord record = new MemcachedStorageRecord(value, expiration);
  final int expiry = record.getExpiry();
  Constraint.isGreaterThan(-1, expiry, "Expiration must be null or positive");
  final String namespace = lookupNamespace(context);
  if (namespace == null) {
    logger.debug("Namespace for context {} does not exist", context);
    return false;
  }
  final String cacheKey = memcachedKey(namespace, key);
  logger.debug("Updating entry at {} for context={}, key={}, exp={}", cacheKey, context, key, expiry);
  return handleAsyncResult(memcacheClient.replace(cacheKey, expiry, record, storageRecordTranscoder));
}

代码示例来源:origin: ECNU-1X/DataX-Masking

break;
case replace:
  future = client.replace(key, expireTime, value);
  break;

代码示例来源: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());
}

代码示例来源:origin: org.infinispan/infinispan-compatibility-mode-it

assertTrue(l.visited.isEmpty());
Future<Boolean> future4 = remote.replace("k", 0, "replacedValue");
assertTrue(future4.get(60, TimeUnit.SECONDS));

相关文章