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

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

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

MemcachedClient.get介绍

[英]Get with a single key and decode using the default transcoder.
[中]用一个键获取,并使用默认转码器进行解码。

代码示例

代码示例来源:origin: aol/micro-server

@Override
public Optional<V> get(String key) {
  return (Optional<V>) Optional.ofNullable(memcachedClient.get(key));
}

代码示例来源:origin: qiujiayu/AutoLoadCache

@SuppressWarnings("unchecked")
@Override
public CacheWrapper<Object> get(final CacheKeyTO cacheKeyTO, Method method) throws CacheCenterConnectionException {
  if (null == cacheKeyTO) {
    return null;
  }
  String cacheKey = cacheKeyTO.getCacheKey();
  if (null == cacheKey || cacheKey.isEmpty()) {
    return null;
  }
  String hfield = cacheKeyTO.getHfield();
  if (null != hfield && hfield.length() > 0) {
    throw new RuntimeException("memcached does not support hash cache.");
  }
  return (CacheWrapper<Object>) memcachedClient.get(cacheKey);
}

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

@SuppressWarnings("unchecked")
@Override
public Session get(final Builder builder) {
 String key = key(builder.sessionId());
 Map<String, String> attrs = (Map<String, String>) memcached.get(key);
 if (attrs == null || attrs.size() == 0) {
  // expired
  return null;
 }
 // touch session
 memcached.touch(key, timeout);
 return builder
   .accessedAt(Long.parseLong(attrs.remove("_accessedAt")))
   .createdAt(Long.parseLong(attrs.remove("_createdAt")))
   .savedAt(Long.parseLong(attrs.remove("_savedAt")))
   .set(attrs)
   .build();
}

代码示例来源:origin: apache/hbase

@Override
public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching,
             boolean repeat, boolean updateCacheMetrics) {
 // Assume that nothing is the block cache
 HFileBlock result = null;
 try (TraceScope traceScope = TraceUtil.createTrace("MemcachedBlockCache.getBlock")) {
  result = client.get(cacheKey.toString(), tc);
 } catch (Exception e) {
  // Catch a pretty broad set of exceptions to limit any changes in the memecache client
  // and how it handles failures from leaking into the read path.
  if (LOG.isDebugEnabled()) {
   LOG.debug("Exception pulling from memcached [ "
     + cacheKey.toString()
     + " ]. Treating as a miss.", e);
  }
  result = null;
 } finally {
  // Update stats if this request doesn't have it turned off 100% of the time
  if (updateCacheMetrics) {
   if (result == null) {
    cacheStats.miss(caching, cacheKey.isPrimary(), cacheKey.getBlockType());
   } else {
    cacheStats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType());
   }
  }
 }
 return result;
}

代码示例来源:origin: aol/micro-server

@Before
public void setup() {
  memcachedClient = mock(MemcachedClient.class);
  stub(memcachedClient.get("key1")).toReturn("value1");
  stub(memcachedClient.get("key2")).toReturn("value2");
  OperationFuture<Boolean> mockedFuture = mock(OperationFuture.class);
  stub(memcachedClient.add("keyAdd", 3600, "valueadd")).toReturn(mockedFuture);
}

代码示例来源:origin: pippo-java/pippo

@Override
public SessionData get(String sessionId) {
  return (SessionData) this.sessions.get(sessionId);
}

代码示例来源:origin: magro/memcached-session-manager

@Override
public byte[] get(String key) {
  return _memcached.get(key, ByteArrayTranscoder.INSTANCE);
}

代码示例来源:origin: magro/memcached-session-manager

@Override
  public Object call() throws Exception {
    return _client.get( sessionId1 );
  }
}, notNullValue() );

代码示例来源:origin: magro/memcached-session-manager

@Override
  public Object call() throws Exception {
    return _client.get( sessionId1 );
  }
}, notNullValue());

代码示例来源:origin: magro/memcached-session-manager

@Override
  public byte[] get(final String key) {
    return _client.get(key, ByteArrayTranscoder.INSTANCE);
  }
};

代码示例来源:origin: magro/memcached-session-manager

@Override
  public byte[] get(final String key) {
    return _client.get(key, ByteArrayTranscoder.INSTANCE);
  }
};

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

public Object get(final String key) {
  return fromCacheValue(client.get(key));
}

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

@Override
protected byte[] restore(final String storageKey) throws ResourceIOException {
  try {
    return castAsByteArray(client.get(storageKey));
  } catch (final OperationTimeoutException ex) {
    throw new MemcachedOperationTimeoutException(ex);
  }
}

代码示例来源:origin: magro/memcached-session-manager

@Test( enabled = true )
public void testInvalidateSessionShouldReleaseLockIssue144() throws IOException, InterruptedException, HttpException {
  _tomcat1.getManager().setLockingMode(LockingMode.AUTO.name());
  final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId();
  assertNotNull( sessionId1, "No session created." );
  final Response response = get( _httpClient, TC_PORT_1, PATH_INVALIDATE, sessionId1 );
  assertNull( response.getResponseSessionId() );
  assertNull(_client.get( sessionId1 ), "Invalidated session should be removed from memcached");
  assertNull(_client.get(new SessionIdFormat().createLockName(sessionId1)), "Lock should be released.");
}

代码示例来源:origin: magro/memcached-session-manager

@Test
public void testInvalidNonStickySessionDoesNotCallOnBackupWithoutLoadedSessionIssue137() throws Exception {
  _service.setStickyInternal( false );
  _service.setLockingMode( LockingMode.NONE, null, false );
  _service.startInternal(new MemcachedStorageClient(_memcachedMock)); // we must put in our mock again
  final String sessionId = "nonStickySessionToTimeOut-n1";
  // For findSession needed
  final Request requestMock = mock(Request.class);
  when(requestMock.getNote(eq(RequestTrackingContextValve.INVOKED))).thenReturn(Boolean.TRUE);
  _service.getTrackingHostValve().storeRequestThreadLocal(requestMock);
  final MemcachedBackupSession session = _service.findSession(sessionId);
  assertNull(session);
  _service.backupSession( sessionId, false, null ).get();
  // check that validity info is not loaded - this would trigger the
  // WARNING: Found no validity info for session id ...
  final String validityKey = new SessionIdFormat().createValidityInfoKeyName( sessionId );
  verify( _memcachedMock, times( 0 ) ).get( eq( validityKey ) );
}

代码示例来源:origin: magro/memcached-session-manager

when( _memcachedMock.get( eq( validityKey ), any ( Transcoder.class) ) ).thenReturn( validityData );

代码示例来源:origin: magro/memcached-session-manager

assertNull( _client.get( sessionId1 ) );
assertNotNull( _client.get( sessionId2 ) );

代码示例来源:origin: magro/memcached-session-manager

@Test
public void testBackupSessionInCouchbase() throws InterruptedException, ExecutionException {
  final MemcachedSessionService service = _tomcat1.getService();
  final MemcachedBackupSession session = createSession( service );
  final String sessionId = "12345";
  session.setId(sessionId);
  session.setAttribute( "foo", "bar" );
  final BackupResult backupResult = service.backupSession( session.getIdInternal(), false, null ).get();
  assertEquals(backupResult.getStatus(), BackupResultStatus.SUCCESS);
  final MemcachedBackupSession loadedSession = transcoderService.deserialize(mc.get(sessionId, ByteArrayTranscoder.INSTANCE), _tomcat1.getManager());
  checkSession(loadedSession, session);
}

代码示例来源:origin: magro/memcached-session-manager

_service.getTrackingHostValve().storeRequestThreadLocal(requestMock);
when(_memcachedMock.get(eq(session.getId()), any(Transcoder.class))).thenReturn(transcoderService.serialize(session));

代码示例来源:origin: magro/memcached-session-manager

@Test(enabled = false) // spurious failures
public void testBackupSessionInCouchbaseCluster() throws Exception {
  final MemcachedSessionService service = _tomcat1.getService();
  cluster.add(setupCouchbase(getMaxCouchbasePort() + 1));
  service.setMemcachedNodes(getMemcachedNodesConfig(getURIs()));
  setupCouchbaseClient();
  waitForReconnect(service.getStorageClient(), cluster.size(), 1000);
  waitForReconnect(mc, cluster.size(), 1000);
  final MemcachedBackupSession session = createSession( service );
  final String sessionId = "12345";
  session.setId(sessionId);
  session.setAttribute( "foo", "bar" );
  final BackupResult backupResult = service.backupSession( session.getIdInternal(), false, null ).get();
  assertEquals(backupResult.getStatus(), BackupResultStatus.SUCCESS);
  final MemcachedBackupSession loadedSession = transcoderService.deserialize(mc.get(sessionId, ByteArrayTranscoder.INSTANCE), _tomcat1.getManager());
  checkSession(loadedSession, session);
}

相关文章