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

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

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

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

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

  1. public Set<String> putIfUntouched(final Map<String, CasPut> values) {
  2. final Set<String> successes = new HashSet<>();
  3. values.forEach((key, vals) -> {
  4. final long cas = ((SpyIdentifiableValue)vals.getIv()).getCasValue().getCas();
  5. final CASResponse response = client.cas(key, cas, vals.getExpirationSeconds(), toCacheValue(vals.getNextToStore()));
  6. if (response == CASResponse.OK) {
  7. successes.add(key);
  8. }
  9. });
  10. return successes;
  11. }

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

  1. /**
  2. * Perform a synchronous CAS operation.
  3. *
  4. * @param <T>
  5. * @param key the key
  6. * @param casId the CAS identifier (from a gets operation)
  7. * @param value the new value
  8. * @param tc the transcoder to serialize and unserialize the value
  9. * @return a CASResponse
  10. * @throws OperationTimeoutException if global operation timeout is exceeded
  11. * @throws IllegalStateException in the rare circumstance where queue is too
  12. * full to accept any more requests
  13. */
  14. @Override
  15. public <T> CASResponse cas(String key, long casId, T value,
  16. Transcoder<T> tc) {
  17. return cas(key, casId, 0, value, tc);
  18. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param value the new value
  7. * @return a CASResponse
  8. * @throws OperationTimeoutException if the global operation timeout is
  9. * exceeded
  10. * @throws IllegalStateException in the rare circumstance where queue
  11. * is too full to accept any more requests
  12. */
  13. public CASResponse cas(String key, long casId, Object value) {
  14. return cas(key, casId, value, transcoder);
  15. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param value the new value
  7. * @return a CASResponse
  8. * @throws OperationTimeoutException if the global operation timeout is
  9. * exceeded
  10. * @throws IllegalStateException in the rare circumstance where queue is too
  11. * full to accept any more requests
  12. */
  13. public CASResponse cas(String key, long casId, Object value) {
  14. return cas(key, casId, value, transcoder);
  15. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param value the new value
  7. * @return a CASResponse
  8. * @throws OperationTimeoutException if the global operation timeout is
  9. * exceeded
  10. * @throws IllegalStateException in the rare circumstance where queue is too
  11. * full to accept any more requests
  12. */
  13. @Override
  14. public CASResponse cas(String key, long casId, Object value) {
  15. return cas(key, casId, value, transcoder);
  16. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param value the new value
  7. * @return a CASResponse
  8. * @throws OperationTimeoutException if the global operation timeout is
  9. * exceeded
  10. * @throws IllegalStateException in the rare circumstance where queue
  11. * is too full to accept any more requests
  12. */
  13. public CASResponse cas(String key, long casId, Object value) {
  14. return cas(key, casId, value, transcoder);
  15. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param value the new value
  7. * @return a CASResponse
  8. * @throws OperationTimeoutException if the global operation timeout is
  9. * exceeded
  10. * @throws IllegalStateException in the rare circumstance where queue
  11. * is too full to accept any more requests
  12. */
  13. public CASResponse cas(String key, long casId, Object value) {
  14. return cas(key, casId, value, transcoder);
  15. }

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

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

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

  1. /**
  2. * Perform a synchronous CAS operation.
  3. *
  4. * @param <T>
  5. * @param key the key
  6. * @param casId the CAS identifier (from a gets operation)
  7. * @param value the new value
  8. * @param tc the transcoder to serialize and unserialize the value
  9. * @return a CASResponse
  10. * @throws OperationTimeoutException if global operation timeout is
  11. * exceeded
  12. * @throws IllegalStateException in the rare circumstance where queue
  13. * is too full to accept any more requests
  14. */
  15. public <T> CASResponse cas(String key, long casId, T value,
  16. Transcoder<T> tc) {
  17. return cas(key, casId, 0, value, tc);
  18. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param value the new value
  7. * @return a CASResponse
  8. * @throws OperationTimeoutException if the global operation timeout is
  9. * exceeded
  10. * @throws IllegalStateException in the rare circumstance where queue is too
  11. * full to accept any more requests
  12. */
  13. @Override
  14. public CASResponse cas(String key, long casId, Object value) {
  15. return cas(key, casId, value, transcoder);
  16. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param exp the expiration of this object
  7. * @param value the new value
  8. * @return a CASResponse
  9. * @throws OperationTimeoutException if the global operation timeout is
  10. * exceeded
  11. * @throws IllegalStateException in the rare circumstance where queue is too
  12. * full to accept any more requests
  13. */
  14. @Override
  15. public CASResponse cas(String key, long casId, int exp, Object value) {
  16. return cas(key, casId, exp, value, transcoder);
  17. }

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

  1. /**
  2. * Perform a synchronous CAS operation.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param value the new value
  7. * @param tc the transcoder to serialize and unserialize the value
  8. * @return a CASResponse
  9. * @throws OperationTimeoutException if global operation timeout is
  10. * exceeded
  11. * @throws IllegalStateException in the rare circumstance where queue
  12. * is too full to accept any more requests
  13. */
  14. public <T> CASResponse cas(String key, long casId, T value,
  15. Transcoder<T> tc) {
  16. return cas(key, casId, 0, value, tc);
  17. }

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

  1. /**
  2. * Perform a synchronous CAS operation.
  3. *
  4. * @param <T>
  5. * @param key the key
  6. * @param casId the CAS identifier (from a gets operation)
  7. * @param value the new value
  8. * @param tc the transcoder to serialize and unserialize the value
  9. * @return a CASResponse
  10. * @throws OperationTimeoutException if global operation timeout is exceeded
  11. * @throws IllegalStateException in the rare circumstance where queue is too
  12. * full to accept any more requests
  13. */
  14. public <T> CASResponse cas(String key, long casId, T value,
  15. Transcoder<T> tc) {
  16. return cas(key, casId, 0, value, tc);
  17. }

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

  1. /**
  2. * Perform a synchronous CAS operation with the default transcoder.
  3. *
  4. * @param key the key
  5. * @param casId the CAS identifier (from a gets operation)
  6. * @param exp the expiration of this object
  7. * @param value the new value
  8. * @return a CASResponse
  9. * @throws OperationTimeoutException if the global operation timeout is
  10. * exceeded
  11. * @throws IllegalStateException in the rare circumstance where queue is too
  12. * full to accept any more requests
  13. */
  14. @Override
  15. public CASResponse cas(String key, long casId, int exp, Object value) {
  16. return cas(key, casId, exp, value, transcoder);
  17. }

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

  1. /**
  2. * Perform a synchronous CAS operation.
  3. *
  4. * @param <T>
  5. * @param key the key
  6. * @param casId the CAS identifier (from a gets operation)
  7. * @param value the new value
  8. * @param tc the transcoder to serialize and unserialize the value
  9. * @return a CASResponse
  10. * @throws OperationTimeoutException if global operation timeout is exceeded
  11. * @throws IllegalStateException in the rare circumstance where queue is too
  12. * full to accept any more requests
  13. */
  14. @Override
  15. public <T> CASResponse cas(String key, long casId, T value,
  16. Transcoder<T> tc) {
  17. return cas(key, casId, 0, value, tc);
  18. }

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

  1. /**
  2. * Perform a synchronous CAS operation.
  3. *
  4. * @param <T>
  5. * @param key the key
  6. * @param casId the CAS identifier (from a gets operation)
  7. * @param value the new value
  8. * @param tc the transcoder to serialize and unserialize the value
  9. * @return a CASResponse
  10. * @throws OperationTimeoutException if global operation timeout is
  11. * exceeded
  12. * @throws IllegalStateException in the rare circumstance where queue
  13. * is too full to accept any more requests
  14. */
  15. public <T> CASResponse cas(String key, long casId, T value,
  16. Transcoder<T> tc) {
  17. return cas(key, casId, 0, value, tc);
  18. }

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

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

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

  1. public void testCas() throws Exception {
  2. MemcachedClient client = bootstrapClient();
  3. client.add("caskey", 10, "casValue").get();
  4. CASValue<Object> val = client.gets("caskey");
  5. assertEquals("casValue", val.getValue());
  6. CASResponse r = client.cas("caskey", val.getCas(), "newValue");
  7. assertEquals(CASResponse.OK, r);
  8. r = client.cas("caskey", val.getCas(), "newValue2");
  9. assertEquals(CASResponse.EXISTS, r);
  10. }

代码示例来源:origin: org.mybatis.caches/mybatis-memcached

  1. /**
  2. * Tries to update an object value in memcached considering the cas validation
  3. *
  4. * Returns true if the object passed the cas validation and was modified.
  5. *
  6. * @param keyString
  7. * @param value
  8. * @return
  9. */
  10. private boolean storeInMemcached(String keyString, ObjectWithCas value) {
  11. if (value != null && value.getObject() != null
  12. && !Serializable.class.isAssignableFrom(value.getObject().getClass())) {
  13. throw new CacheException("Object of type '" + value.getObject().getClass().getName()
  14. + "' that's non-serializable is not supported by Memcached");
  15. }
  16. CASResponse response;
  17. if (configuration.isCompressionEnabled()) {
  18. response = client.cas(keyString, value.getCas(), value.getObject(), new CompressorTranscoder());
  19. } else {
  20. response = client.cas(keyString, value.getCas(), value.getObject());
  21. }
  22. return (response.equals(CASResponse.OBSERVE_MODIFIED) || response.equals(CASResponse.OK));
  23. }

相关文章