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

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

本文整理了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

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

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

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

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

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

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

  1. @Override
  2. public Status update(
  3. String table, String key, Map<String, ByteIterator> values) {
  4. key = createQualifiedKey(table, key);
  5. try {
  6. OperationFuture<Boolean> future =
  7. memcachedClient().replace(key, objectExpirationTime, toJson(values));
  8. return getReturnCode(future);
  9. } catch (Exception e) {
  10. logger.error("Error updating value with key: " + key, e);
  11. return Status.ERROR;
  12. }
  13. }

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

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

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

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

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

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

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

  1. public void testReplace() throws Exception {
  2. MemcachedClient client = bootstrapClient();
  3. Future<Boolean> b = client.replace("key", 10, "newVal");
  4. assertTrue(b.get());
  5. b = client.replace("nonExistentkey", 10, "val");
  6. assertFalse(b.get());
  7. b = client.replace("key", 10, "myStringValue");
  8. assertTrue(b.get());
  9. }

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

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

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

  1. /** {@inheritDoc} */
  2. @Override
  3. public boolean update(@Nonnull @NotEmpty final String context,
  4. @Nonnull @NotEmpty final String key,
  5. @Nonnull @NotEmpty final String value,
  6. @Nullable @Positive final Long expiration) throws IOException {
  7. Constraint.isNotNull(StringSupport.trimOrNull(context), "Context cannot be null or empty");
  8. Constraint.isNotNull(StringSupport.trimOrNull(key), "Key cannot be null or empty");
  9. Constraint.isNotNull(StringSupport.trimOrNull(value), "Value cannot be null or empty");
  10. final MemcachedStorageRecord record = new MemcachedStorageRecord(value, expiration);
  11. final int expiry = record.getExpiry();
  12. Constraint.isGreaterThan(-1, expiry, "Expiration must be null or positive");
  13. final String namespace = lookupNamespace(context);
  14. if (namespace == null) {
  15. logger.debug("Namespace for context {} does not exist", context);
  16. return false;
  17. }
  18. final String cacheKey = memcachedKey(namespace, key);
  19. logger.debug("Updating entry at {} for context={}, key={}, exp={}", cacheKey, context, key, expiry);
  20. return handleAsyncResult(memcacheClient.replace(cacheKey, expiry, record, storageRecordTranscoder));
  21. }

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

  1. break;
  2. case replace:
  3. future = client.replace(key, expireTime, value);
  4. break;

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

  1. public void testGets() throws Exception {
  2. MemcachedClient client = bootstrapClient();
  3. client.add("getskey", 10, "casValue").get();
  4. CASValue<Object> val = client.gets("getskey");
  5. long oldCas = val.getCas();
  6. assertEquals("casValue", val.getValue());
  7. client.replace("getskey", 10, "myNewVal").get();
  8. val = client.gets("getskey");
  9. assertEquals(oldCas + 1, val.getCas());
  10. assertEquals("myNewVal", val.getValue());
  11. }

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

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

相关文章