本文整理了Java中net.spy.memcached.MemcachedClient.set()
方法的一些代码示例,展示了MemcachedClient.set()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MemcachedClient.set()
方法的具体详情如下:
包路径:net.spy.memcached.MemcachedClient
类名称:MemcachedClient
方法名:set
[英]Set an object in the cache (using the default transcoder) regardless of any existing value.
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 set(String key, Object value, int expiration) {
client.set(key, expiration, value, tc);
}
代码示例来源:origin: ninjaframework/ninja
public boolean safeSet(String key, Object value, int expiration) {
Future<Boolean> future = client.set(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 save(final Session session) {
String key = key(session);
Map<String, String> attrs = new HashMap<>(session.attributes());
attrs.put("_createdAt", Long.toString(session.createdAt()));
attrs.put("_accessedAt", Long.toString(session.accessedAt()));
attrs.put("_savedAt", Long.toString(session.savedAt()));
memcached.set(key, timeout, attrs);
}
代码示例来源:origin: qiujiayu/AutoLoadCache
@Override
public void setCache(final CacheKeyTO cacheKeyTO, final CacheWrapper<Object> result, final Method method) throws CacheCenterConnectionException {
if (null == cacheKeyTO) {
return;
}
String cacheKey = cacheKeyTO.getCacheKey();
if (null == cacheKey || cacheKey.isEmpty()) {
return;
}
String hfield = cacheKeyTO.getHfield();
if (null != hfield && hfield.length() > 0) {
throw new RuntimeException("memcached does not support hash cache.");
}
if (result.getExpire() >= 0) {
memcachedClient.set(cacheKey, result.getExpire(), result);
}
}
代码示例来源:origin: apache/httpcomponents-client
@Override
protected void store(final String storageKey, final byte[] storageObject) throws ResourceIOException {
client.set(storageKey, 0, storageObject);
}
代码示例来源:origin: magro/memcached-session-manager
@Override
public Future<Boolean> set(String key, int exp, byte[] o) {
return _memcached.set(key, exp, o, ByteArrayTranscoder.INSTANCE);
}
代码示例来源:origin: apache/httpcomponents-client
@Override
protected Cancellable store(final String storageKey, final byte[] storageObject, final FutureCallback<Boolean> callback) {
return operation(client.set(storageKey, 0, storageObject), callback);
}
代码示例来源:origin: pippo-java/pippo
@Override
public void save(SessionData sessionData) {
this.sessions.set(sessionData.getId(), idleTime, sessionData);
}
代码示例来源:origin: objectify/objectify
public void put(final String key, final Object value) {
client.set(key, 0, toCacheValue(value));
}
代码示例来源:origin: objectify/objectify
private IdentifiableValue getIdentifiable(final String key) {
final CASValue<Object> casValue = client.gets(key);
if (casValue != null) {
return new SpyIdentifiableValue(casValue);
} else {
client.set(key, 0, NULL_VALUE); // use the fake null so that no other fetches get confused
final CASValue<Object> try2 = client.gets(key);
return try2 == null ? null : new SpyIdentifiableValue(try2);
}
}
代码示例来源:origin: magro/memcached-session-manager
/**
* Test for issue #105: Make memcached node optional for single-node setup
* http://code.google.com/p/memcached-session-manager/issues/detail?id=105
*/
@Test
public void testBackupSessionFailureWithoutMemcachedNodeIdConfigured105() throws Exception {
_service.setMemcachedNodes( "127.0.0.1:11211" );
_service.setSessionBackupAsync(false);
_service.startInternal(new MemcachedStorageClient(_memcachedMock));
final MemcachedBackupSession session = createSession( _service );
session.access();
session.endAccess();
session.setAttribute( "foo", "bar" );
@SuppressWarnings( "unchecked" )
final OperationFuture<Boolean> futureMock = mock( OperationFuture.class );
when( futureMock.get( ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception.")));
when( futureMock.get( anyInt(), any( TimeUnit.class ) ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception.")));
when( _memcachedMock.set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( futureMock );
final BackupResult backupResult = _service.backupSession( session.getIdInternal(), false, null ).get();
assertEquals(backupResult.getStatus(), BackupResultStatus.FAILURE);
verify( _memcachedMock, times( 1 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) );
}
代码示例来源:origin: magro/memcached-session-manager
@SuppressWarnings("unchecked")
@BeforeMethod
public void setup() throws Exception {
final StandardContext context = createContext();
context.setBackgroundProcessorDelay( 1 ); // needed for test of updateExpiration
final SessionManager manager = createSessionManager(context);
_service = manager.getMemcachedSessionService();
_service.setMemcachedNodes( "n1:127.0.0.1:11211" );
_service.setSessionBackupAsync( false );
_service.setSticky( true );
_memcachedMock = mock( MemcachedClient.class );
final OperationFuture<Boolean> setResultMock = mock( OperationFuture.class );
when( setResultMock.get( ) ).thenReturn( Boolean.TRUE );
when( setResultMock.get( anyInt(), any( TimeUnit.class ) ) ).thenReturn( Boolean.TRUE );
when( _memcachedMock.set( any( String.class ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( setResultMock );
final OperationFuture<Boolean> deleteResultMock = mock( OperationFuture.class );
when( deleteResultMock.get() ).thenReturn( Boolean.TRUE );
when( _memcachedMock.delete( anyString() ) ).thenReturn( deleteResultMock );
startInternal( manager, _memcachedMock );
_executor = Executors.newCachedThreadPool();
}
代码示例来源:origin: magro/memcached-session-manager
verify( _memcachedMock, times( 1 ) ).set( eq( validityKey ), eq( 0 ), any(), any( Transcoder.class ) );
verify( _memcachedMock, times( 1 ) ).set( eq( backupValidityKey ), eq( 0 ), any(), any( Transcoder.class ) );
代码示例来源:origin: magro/memcached-session-manager
session.setAttribute( "foo", "bar" );
_service.backupSession( session.getIdInternal(), false, null ).get();
verify( _memcachedMock, times( 1 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) );
session.setAttribute( "bar", "baz" );
_service.backupSession( session.getIdInternal(), false, null ).get();
verify( _memcachedMock, times( 2 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) );
verify( _memcachedMock, times( 2 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) );
代码示例来源:origin: magro/memcached-session-manager
verify( _memcachedMock, times( 1 ) ).set( eq( sessionId ), eq( 0 ), any(), any( Transcoder.class ) );
verify( _memcachedMock, times( 1 ) ).set( eq( validityKey ), eq( 0 ), any(), any( Transcoder.class ) );
verify( _memcachedMock, times( 1 ) ).set( eq( backupSessionKey ), eq( 0 ), any(), any( Transcoder.class ) );
final String backupValidityKey = new SessionIdFormat().createBackupKey( validityKey );
verify( _memcachedMock, times( 1 ) ).set( eq( backupValidityKey ), eq( 0 ), any(), any( Transcoder.class ) );
代码示例来源:origin: magro/memcached-session-manager
verify( _memcachedMock, times( 1 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) );
verify( _memcachedMock, times( 1 ) ).set( eq( new SessionIdFormat().createValidityInfoKeyName( session.getId() ) ), anyInt(), any(), any( Transcoder.class ) );
代码示例来源:origin: org.apache.apex/malhar-contrib
@SuppressWarnings("unchecked")
@Override
public void put(Object key, Object value)
{
try {
memcacheClient.set(key.toString(), keyExpiryTime, value).get();
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
代码示例来源:origin: yahoo/fili
@Override
public boolean set(String key, T value) throws IllegalStateException {
try {
// Omitting null checking for key since it should be rare.
// An exception will be thrown by the memcached client.
return client.set(key, EXPIRATION, value).get();
} catch (Exception e) {
LOG.warn("set failed {} {}", key, e.toString());
throw new IllegalStateException(e);
}
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testSet() throws Exception {
MemcachedClient client = bootstrapClient();
Future<Boolean> f = client.set("key", 10, "myStringValue");
assertTrue(f.get());
}
代码示例来源:origin: org.infinispan/infinispan-compatibility-mode-it
public void testMemcachedPutEmbeddedGet() throws Exception {
// 1. Put with Memcached
for (int i = 0; i != numEntries; i++) {
Future<Boolean> f = cacheFactory2.getMemcachedClient().set("k" + i, 0, "v" + i);
assertTrue(f.get(60, TimeUnit.SECONDS));
}
// 2. Get with Embedded from a different node
for (int i = 0; i != numEntries; i++) {
assertEquals("v" + i, cacheFactory1.getEmbeddedCache().get("k" + i));
cacheFactory1.getEmbeddedCache().remove("k" + i);
}
}
内容来源于网络,如有侵权,请联系作者删除!