Search in sources :

Example 26 with RedisConnection

use of org.springframework.data.redis.connection.RedisConnection in project rdbcache by rdbcache.

the class RedisOps method ensureNotifyKeySpaceEventsEx.

// make sure config set notify-keyspace-events Ex
// 
public void ensureNotifyKeySpaceEventsEx() {
    RedisConnection connection = AppCtx.getStringRedisTemplate().getConnectionFactory().getConnection();
    Properties properties = connection.getConfig("notify-keyspace-events");
    String config = "";
    for (String key : properties.stringPropertyNames()) {
        String value = properties.getProperty(key);
        if (value.equals("notify-keyspace-events")) {
            config = value;
            break;
        }
    }
    if (config.contains("E") && (config.contains("A") || config.contains("x"))) {
        return;
    }
    if (!config.contains("E")) {
        config += "E";
    }
    if (!config.contains("A") && !config.contains("x")) {
        config += "x";
    }
    connection.setConfig("notify-keyspace-events", config);
    LOGGER.trace("setConfig notify-keyspace-events " + config);
}
Also used : RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 27 with RedisConnection

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

the class RedisHttpSessionConfigurationXmlCustomExpireTests method connectionFactory.

static RedisConnectionFactory connectionFactory() {
    RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
    RedisConnection connection = mock(RedisConnection.class);
    given(factory.getConnection()).willReturn(connection);
    given(connection.getConfig(anyString())).willReturn(new Properties());
    return factory;
}
Also used : Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 28 with RedisConnection

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

the class RedisHttpSessionConfigurationClassPathXmlApplicationContextTests method connectionFactory.

static RedisConnectionFactory connectionFactory() {
    RedisConnectionFactory factory = mock(RedisConnectionFactory.class);
    RedisConnection connection = mock(RedisConnection.class);
    given(factory.getConnection()).willReturn(connection);
    given(connection.getConfig(anyString())).willReturn(new Properties());
    return factory;
}
Also used : Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 29 with RedisConnection

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

the class RedisHttpSessionConfigurationTests method mockRedisConnectionFactory.

private static RedisConnectionFactory mockRedisConnectionFactory() {
    RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class);
    RedisConnection connection = mock(RedisConnection.class);
    given(connectionFactory.getConnection()).willReturn(connection);
    given(connection.getConfig(anyString())).willReturn(new Properties());
    return connectionFactory;
}
Also used : Properties(java.util.Properties) SpringSessionRedisConnectionFactory(org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisConnection(org.springframework.data.redis.connection.RedisConnection)

Example 30 with RedisConnection

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

the class RedisTokenStore method getAccessToken.

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

Aggregations

RedisConnection (org.springframework.data.redis.connection.RedisConnection)41 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)9 RedisConnectionFailureException (org.springframework.data.redis.RedisConnectionFailureException)8 Properties (java.util.Properties)7 DataAccessException (org.springframework.dao.DataAccessException)7 RedisCallback (org.springframework.data.redis.core.RedisCallback)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 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 Logger (org.slf4j.Logger)2