@Override protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { return connection.get(rawKey); } }, true);
final byte[] currValue = redisConnection.get(k);
@Override public byte[] get(String name, byte[] key) { Assert.notNull(name, "Name must not be null!"); Assert.notNull(key, "Key must not be null!"); return execute(name, connection -> connection.get(key)); }
final byte[] currValue = redisConnection.get(key); final RedisStateMap currStateMap = serDe.deserialize(currValue); final long currVersion = currStateMap == null ? -1L : currStateMap.getVersion();
@Override public byte[] get(byte[] key) { return convertAndReturn(delegate.get(key), identityConverter); }
@Override public String get(String key) { return convertAndReturn(delegate.get(serialize(key)), bytesToString); }
@Override public <K, V> V get(final K key, final Serializer<K> keySerializer, final Deserializer<V> valueDeserializer) throws IOException { return withConnection(redisConnection -> { final byte[] k = serialize(key, keySerializer); final byte[] v = redisConnection.get(k); return valueDeserializer.deserialize(v); }); }
@Override public OAuth2Authentication readAuthentication(String token) { byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(serializeKey(AUTH + token)); } finally { conn.close(); } OAuth2Authentication auth = deserializeAuthentication(bytes); return auth; }
public OAuth2Authentication readAuthenticationForRefreshToken(String token) { RedisConnection conn = getConnection(); try { byte[] bytes = conn.get(serializeKey(REFRESH_AUTH + token)); OAuth2Authentication auth = deserializeAuthentication(bytes); return auth; } finally { conn.close(); } }
@Override public OAuth2AccessToken readAccessToken(String tokenValue) { byte[] key = serializeKey(ACCESS + tokenValue); byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(key); } finally { conn.close(); } OAuth2AccessToken accessToken = deserializeAccessToken(bytes); return accessToken; }
@Override public OAuth2RefreshToken readRefreshToken(String tokenValue) { byte[] key = serializeKey(REFRESH + tokenValue); byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(key); } finally { conn.close(); } OAuth2RefreshToken refreshToken = deserializeRefreshToken(bytes); return refreshToken; }
@Override public <K, V> AtomicCacheEntry<K, V, byte[]> fetch(final K key, final Serializer<K> keySerializer, final Deserializer<V> valueDeserializer) throws IOException { return withConnection(redisConnection -> { final byte[] k = serialize(key, keySerializer); final byte[] v = redisConnection.get(k); if (v == null) { return null; } // for Redis we are going to use the raw bytes of the value as the revision return new AtomicCacheEntry<>(key, valueDeserializer.deserialize(v), v); }); }
@Override public StateMap getState(final String componentId) throws IOException { return withConnection(redisConnection -> { final byte[] key = getComponentKey(componentId).getBytes(StandardCharsets.UTF_8); final byte[] value = redisConnection.get(key); final RedisStateMap stateMap = serDe.deserialize(value); if (stateMap == null) { return new RedisStateMap.Builder().encodingVersion(ENCODING_VERSION).build(); } else { return stateMap; } }); }
@Override public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) { Assert.notNull(name, "Name must not be null!"); Assert.notNull(key, "Key must not be null!"); Assert.notNull(value, "Value must not be null!"); return execute(name, connection -> { if (isLockingCacheWriter()) { doLock(name, connection); } try { if (connection.setNX(key, value)) { if (shouldExpireWithin(ttl)) { connection.pExpire(key, ttl.toMillis()); } return null; } return connection.get(key); } finally { if (isLockingCacheWriter()) { doUnlock(name, connection); } } }); }
private void removeAccessTokenUsingRefreshToken(String refreshToken) { byte[] key = serializeKey(REFRESH_TO_ACCESS + refreshToken); List<Object> results = null; RedisConnection conn = getConnection(); try { conn.openPipeline(); conn.get(key); conn.del(key); results = conn.closePipeline(); } finally { conn.close(); } if (results == null) { return; } byte[] bytes = (byte[]) results.get(0); String accessToken = deserializeString(bytes); if (accessToken != null) { removeAccessToken(accessToken); } }
final byte[] existingValue = redisConnection.get(kv.getKey());
@Override public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) { String key = authenticationKeyGenerator.extractKey(authentication); byte[] serializedKey = serializeKey(AUTH_TO_ACCESS + key); byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(serializedKey); } finally { conn.close(); } OAuth2AccessToken accessToken = deserializeAccessToken(bytes); if (accessToken != null) { OAuth2Authentication storedAuthentication = readAuthentication(accessToken.getValue()); if ((storedAuthentication == null || !key.equals(authenticationKeyGenerator.extractKey(storedAuthentication)))) { // Keep the stores consistent (maybe the same user is // represented by this authentication but the details have // changed) storeAccessToken(accessToken, authentication); } } return accessToken; }
public byte[] doInRedis(RedisConnection connection) throws DataAccessException { RedisSerializer<String> serializer = getRedisSerializer(); byte[] keyStr = serializer.serialize(key); byte[] value = connection.get(keyStr); return value; } });
public T doInRedis(RedisConnection connection) throws DataAccessException { RedisSerializer<String> serializer = getRedisSerializer(); byte[] keyStr = serializer.serialize(key); byte[] value = connection.get(keyStr); if (value == null) { return null; } String valueStr = serializer.deserialize(value); return (T) JSON.parseObject(valueStr, clazz); } });