Search in sources :

Example 1 with RedisConnection

use of org.springframework.data.redis.connection.RedisConnection in project spring-boot by spring-projects.

the class RedisHealthIndicator method doHealthCheck.

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    RedisConnection connection = RedisConnectionUtils.getConnection(this.redisConnectionFactory);
    try {
        if (connection instanceof RedisClusterConnection) {
            ClusterInfo clusterInfo = ((RedisClusterConnection) connection).clusterGetClusterInfo();
            builder.up().withDetail("cluster_size", clusterInfo.getClusterSize()).withDetail("slots_up", clusterInfo.getSlotsOk()).withDetail("slots_fail", clusterInfo.getSlotsFail());
        } else {
            Properties info = connection.info();
            builder.up().withDetail(VERSION, info.getProperty(REDIS_VERSION));
        }
    } finally {
        RedisConnectionUtils.releaseConnection(connection, this.redisConnectionFactory);
    }
}
Also used : RedisClusterConnection(org.springframework.data.redis.connection.RedisClusterConnection) ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) Properties(java.util.Properties) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 2 with RedisConnection

use of org.springframework.data.redis.connection.RedisConnection in project spring-boot by spring-projects.

the class RedisHealthIndicatorTests method redisIsUp.

@Test
public void redisIsUp() throws Exception {
    Properties info = new Properties();
    info.put("redis_version", "2.8.9");
    RedisConnection redisConnection = mock(RedisConnection.class);
    RedisConnectionFactory redisConnectionFactory = mock(RedisConnectionFactory.class);
    given(redisConnectionFactory.getConnection()).willReturn(redisConnection);
    given(redisConnection.info()).willReturn(info);
    RedisHealthIndicator healthIndicator = new RedisHealthIndicator(redisConnectionFactory);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("version")).isEqualTo("2.8.9");
    verify(redisConnectionFactory).getConnection();
    verify(redisConnection).info();
}
Also used : Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisConnection(org.springframework.data.redis.connection.RedisConnection) Test(org.junit.Test)

Example 3 with RedisConnection

use of org.springframework.data.redis.connection.RedisConnection in project spring-security-oauth by spring-projects.

the class RedisTokenStore method removeRefreshToken.

public void removeRefreshToken(String tokenValue) {
    byte[] refreshKey = serializeKey(REFRESH + tokenValue);
    byte[] refreshAuthKey = serializeKey(REFRESH_AUTH + tokenValue);
    byte[] refresh2AccessKey = serializeKey(REFRESH_TO_ACCESS + tokenValue);
    byte[] access2RefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue);
    RedisConnection conn = getConnection();
    try {
        conn.openPipeline();
        conn.del(refreshKey);
        conn.del(refreshAuthKey);
        conn.del(refresh2AccessKey);
        conn.del(access2RefreshKey);
        conn.closePipeline();
    } finally {
        conn.close();
    }
}
Also used : RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 4 with RedisConnection

use of org.springframework.data.redis.connection.RedisConnection in project spring-security-oauth by spring-projects.

the class RedisTokenStore method readRefreshToken.

@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;
}
Also used : ExpiringOAuth2RefreshToken(org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken) OAuth2RefreshToken(org.springframework.security.oauth2.common.OAuth2RefreshToken) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 5 with RedisConnection

use of org.springframework.data.redis.connection.RedisConnection in project spring-security-oauth by spring-projects.

the class RedisTokenStore method readAccessToken.

@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;
}
Also used : OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Aggregations

RedisConnection (org.springframework.data.redis.connection.RedisConnection)46 RedisCallback (org.springframework.data.redis.core.RedisCallback)10 RedisConnectionFailureException (org.springframework.data.redis.RedisConnectionFailureException)9 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)9 Properties (java.util.Properties)8 DataAccessException (org.springframework.dao.DataAccessException)7 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)7 Test (org.junit.Test)5 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)4 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)4 ExpiringOAuth2RefreshToken (org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken)3 Jedis (redis.clients.jedis.Jedis)3 com.alicp.jetcache (com.alicp.jetcache)2 AbstractExternalCache (com.alicp.jetcache.external.AbstractExternalCache)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Function (java.util.function.Function)2