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

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

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

MemcachedClient.cas介绍

[英]Perform a synchronous CAS operation with the default transcoder.
[中]使用默认转码器执行同步CAS操作。

代码示例

代码示例来源:origin: apache/httpcomponents-client

@Override
protected boolean updateCAS(
    final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException {
  final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject);
  return casResult == CASResponse.OK;
}

代码示例来源:origin: objectify/objectify

public Set<String> putIfUntouched(final Map<String, CasPut> values) {
  final Set<String> successes = new HashSet<>();
  values.forEach((key, vals) -> {
    final long cas = ((SpyIdentifiableValue)vals.getIv()).getCasValue().getCas();
    final CASResponse response = client.cas(key, cas, vals.getExpirationSeconds(), toCacheValue(vals.getNextToStore()));
    if (response == CASResponse.OK) {
      successes.add(key);
    }
  });
  return successes;
}

代码示例来源:origin: net.spy/spymemcached

/**
 * Perform a synchronous CAS operation.
 *
 * @param <T>
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @param tc the transcoder to serialize and unserialize the value
 * @return a CASResponse
 * @throws OperationTimeoutException if global operation timeout is exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public <T> CASResponse cas(String key, long casId, T value,
  Transcoder<T> tc) {
 return cas(key, casId, 0, value, tc);
}

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

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue
 *         is too full to accept any more requests
 */
public CASResponse cas(String key, long casId, Object value) {
  return cas(key, casId, value, transcoder);
}

代码示例来源:origin: com.google.code.simple-spring-memcached/spymemcached

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
public CASResponse cas(String key, long casId, Object value) {
 return cas(key, casId, value, transcoder);
}

代码示例来源:origin: net.spy/spymemcached

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public CASResponse cas(String key, long casId, Object value) {
 return cas(key, casId, value, transcoder);
}

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

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue
 *         is too full to accept any more requests
 */
public CASResponse cas(String key, long casId, Object value) {
  return cas(key, casId, value, transcoder);
}

代码示例来源:origin: naver/arcus-java-client

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key   the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *                                   exceeded
 * @throws IllegalStateException     in the rare circumstance where queue
 *                                   is too full to accept any more requests
 */
public CASResponse cas(String key, long casId, Object value) {
 return cas(key, casId, value, transcoder);
}

代码示例来源:origin: naver/arcus-java-client

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key   the key
 * @param casId the CAS identifier (from a gets operation)
 * @param exp   the expiration of this object
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is exceeded
 * @throws IllegalStateException     in the rare circumstance where queue is too
 *                                   full to accept any more requests
 */
public CASResponse cas(String key, long casId, int exp, Object value) {
 return cas(key, casId, exp, value, transcoder);
}

代码示例来源:origin: naver/arcus-java-client

/**
 * Perform a synchronous CAS operation.
 *
 * @param <T>
 * @param key   the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @param tc    the transcoder to serialize and unserialize the value
 * @return a CASResponse
 * @throws OperationTimeoutException if global operation timeout is
 *                                   exceeded
 * @throws IllegalStateException     in the rare circumstance where queue
 *                                   is too full to accept any more requests
 */
public <T> CASResponse cas(String key, long casId, T value,
              Transcoder<T> tc) {
 return cas(key, casId, 0, value, tc);
}

代码示例来源:origin: com.amazonaws/elasticache-java-cluster-client

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public CASResponse cas(String key, long casId, Object value) {
 return cas(key, casId, value, transcoder);
}

代码示例来源:origin: net.spy/spymemcached

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param exp the expiration of this object
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public CASResponse cas(String key, long casId, int exp, Object value) {
 return cas(key, casId, exp, value, transcoder);
}

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

/**
 * Perform a synchronous CAS operation.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @param tc the transcoder to serialize and unserialize the value
 * @return a CASResponse
 * @throws OperationTimeoutException if global operation timeout is
 *         exceeded
 * @throws IllegalStateException in the rare circumstance where queue
 *         is too full to accept any more requests
 */
public <T> CASResponse cas(String key, long casId, T value,
    Transcoder<T> tc) {
  return cas(key, casId, 0, value, tc);
}

代码示例来源:origin: com.google.code.simple-spring-memcached/spymemcached

/**
 * Perform a synchronous CAS operation.
 *
 * @param <T>
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @param tc the transcoder to serialize and unserialize the value
 * @return a CASResponse
 * @throws OperationTimeoutException if global operation timeout is exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
public <T> CASResponse cas(String key, long casId, T value,
  Transcoder<T> tc) {
 return cas(key, casId, 0, value, tc);
}

代码示例来源:origin: com.amazonaws/elasticache-java-cluster-client

/**
 * Perform a synchronous CAS operation with the default transcoder.
 *
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param exp the expiration of this object
 * @param value the new value
 * @return a CASResponse
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public CASResponse cas(String key, long casId, int exp, Object value) {
 return cas(key, casId, exp, value, transcoder);
}

代码示例来源:origin: com.amazonaws/elasticache-java-cluster-client

/**
 * Perform a synchronous CAS operation.
 *
 * @param <T>
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @param tc the transcoder to serialize and unserialize the value
 * @return a CASResponse
 * @throws OperationTimeoutException if global operation timeout is exceeded
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public <T> CASResponse cas(String key, long casId, T value,
  Transcoder<T> tc) {
 return cas(key, casId, 0, value, tc);
}

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

/**
 * Perform a synchronous CAS operation.
 *
 * @param <T>
 * @param key the key
 * @param casId the CAS identifier (from a gets operation)
 * @param value the new value
 * @param tc the transcoder to serialize and unserialize the value
 * @return a CASResponse
 * @throws OperationTimeoutException if global operation timeout is
 *         exceeded
 * @throws IllegalStateException in the rare circumstance where queue
 *         is too full to accept any more requests
 */
public <T> CASResponse cas(String key, long casId, T value,
    Transcoder<T> tc) {
  return cas(key, casId, 0, value, tc);
}

代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5-cache

@Override
protected boolean updateCAS(
    final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException {
  final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject);
  return casResult == CASResponse.OK;
}

代码示例来源: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: org.mybatis.caches/mybatis-memcached

/**
 * Tries to update an object value in memcached considering the cas validation
 *
 * Returns true if the object passed the cas validation and was modified.
 *
 * @param keyString
 * @param value
 * @return
 */
private boolean storeInMemcached(String keyString, ObjectWithCas value) {
 if (value != null && value.getObject() != null
   && !Serializable.class.isAssignableFrom(value.getObject().getClass())) {
  throw new CacheException("Object of type '" + value.getObject().getClass().getName()
    + "' that's non-serializable is not supported by Memcached");
 }
 CASResponse response;
 if (configuration.isCompressionEnabled()) {
  response = client.cas(keyString, value.getCas(), value.getObject(), new CompressorTranscoder());
 } else {
  response = client.cas(keyString, value.getCas(), value.getObject());
 }
 return (response.equals(CASResponse.OBSERVE_MODIFIED) || response.equals(CASResponse.OK));
}

相关文章