use of org.springframework.data.redis.connection.RedisConnection in project spring-security-oauth by spring-projects.
the class RedisTokenStore method findTokensByClientId.
@Override
public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
byte[] key = serializeKey(CLIENT_ID_TO_ACCESS + clientId);
List<byte[]> byteList = null;
RedisConnection conn = getConnection();
try {
byteList = conn.lRange(key, 0, -1);
} finally {
conn.close();
}
if (byteList == null || byteList.size() == 0) {
return Collections.<OAuth2AccessToken>emptySet();
}
List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(byteList.size());
for (byte[] bytes : byteList) {
OAuth2AccessToken accessToken = deserializeAccessToken(bytes);
accessTokens.add(accessToken);
}
return Collections.<OAuth2AccessToken>unmodifiableCollection(accessTokens);
}
use of org.springframework.data.redis.connection.RedisConnection in project spring-security-oauth by spring-projects.
the class RedisTokenStore method removeAccessTokenUsingRefreshToken.
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);
}
}
use of org.springframework.data.redis.connection.RedisConnection in project spring-security-oauth by spring-projects.
the class RedisTokenStore method readAuthentication.
@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;
}
use of org.springframework.data.redis.connection.RedisConnection in project spring-integration by spring-projects.
the class RedisAvailableTests method awaitContainerSubscribedNoWait.
private void awaitContainerSubscribedNoWait(RedisMessageListenerContainer container) throws InterruptedException {
RedisConnection connection = null;
int n = 0;
while (n++ < 300 && (connection = TestUtils.getPropertyValue(container, "subscriptionTask.connection", RedisConnection.class)) == null) {
Thread.sleep(100);
}
assertNotNull("RedisMessageListenerContainer Failed to Connect", connection);
n = 0;
while (n++ < 300 && !connection.isSubscribed()) {
Thread.sleep(100);
}
assertTrue("RedisMessageListenerContainer Failed to Subscribe", n < 300);
}
use of org.springframework.data.redis.connection.RedisConnection in project springBoot-learn-demo by nbfujx.
the class RedisLock method getSet.
private String getSet(final String key, final String value) {
Object obj = null;
try {
obj = redisTemplate.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
StringRedisSerializer serializer = new StringRedisSerializer();
byte[] ret = connection.getSet(serializer.serialize(key), serializer.serialize(value));
connection.close();
return serializer.deserialize(ret);
}
});
} catch (Exception e) {
logger.error("setNX redis error, key : {}", key);
}
return obj != null ? (String) obj : null;
}
Aggregations