Search in sources :

Example 6 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project spring-session by spring-projects.

the class IndexDocTests method newReactiveRedisOperationsSessionRepository.

@Test
@SuppressWarnings("unused")
public void newReactiveRedisOperationsSessionRepository() {
    LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
    RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext.<String, Object>newSerializationContext(new JdkSerializationRedisSerializer()).build();
    // tag::new-reactiveredisoperationssessionrepository[]
    // ... create and configure connectionFactory and serializationContext ...
    ReactiveRedisTemplate<String, Object> redisTemplate = new ReactiveRedisTemplate<>(connectionFactory, serializationContext);
    ReactiveSessionRepository<? extends Session> repository = new ReactiveRedisOperationsSessionRepository(redisTemplate);
// end::new-reactiveredisoperationssessionrepository[]
}
Also used : ReactiveRedisTemplate(org.springframework.data.redis.core.ReactiveRedisTemplate) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) LettuceConnectionFactory(org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory) ReactiveRedisOperationsSessionRepository(org.springframework.session.data.redis.ReactiveRedisOperationsSessionRepository) Test(org.junit.Test)

Example 7 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project spring-session by spring-projects.

the class RedisOperationsSessionRepositoryTests method onMessageCreated.

@Test
public void onMessageCreated() throws Exception {
    MapSession session = this.cached;
    byte[] pattern = "".getBytes("UTF-8");
    String channel = "spring:session:event:created:" + session.getId();
    JdkSerializationRedisSerializer defaultSerailizer = new JdkSerializationRedisSerializer();
    this.redisRepository.setDefaultSerializer(defaultSerailizer);
    byte[] body = defaultSerailizer.serialize(new HashMap());
    DefaultMessage message = new DefaultMessage(channel.getBytes("UTF-8"), body);
    this.redisRepository.setApplicationEventPublisher(this.publisher);
    this.redisRepository.onMessage(message, pattern);
    verify(this.publisher).publishEvent(this.event.capture());
    assertThat(this.event.getValue().getSessionId()).isEqualTo(session.getId());
}
Also used : DefaultMessage(org.springframework.data.redis.connection.DefaultMessage) HashMap(java.util.HashMap) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) MapSession(org.springframework.session.MapSession) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project spring-boot by spring-projects.

the class RedisCacheConfiguration method createConfiguration.

private org.springframework.data.redis.cache.RedisCacheConfiguration createConfiguration(CacheProperties cacheProperties, ClassLoader classLoader) {
    Redis redisProperties = cacheProperties.getRedis();
    org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration.defaultCacheConfig();
    config = config.serializeValuesWith(SerializationPair.fromSerializer(new JdkSerializationRedisSerializer(classLoader)));
    if (redisProperties.getTimeToLive() != null) {
        config = config.entryTtl(redisProperties.getTimeToLive());
    }
    if (redisProperties.getKeyPrefix() != null) {
        config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());
    }
    if (!redisProperties.isCacheNullValues()) {
        config = config.disableCachingNullValues();
    }
    if (!redisProperties.isUseKeyPrefix()) {
        config = config.disableKeyPrefix();
    }
    return config;
}
Also used : JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) Redis(org.springframework.boot.autoconfigure.cache.CacheProperties.Redis)

Example 9 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project spring-boot by spring-projects.

the class RedisReactiveAutoConfiguration method reactiveRedisTemplate.

@Bean
@ConditionalOnMissingBean(name = "reactiveRedisTemplate")
@ConditionalOnBean(ReactiveRedisConnectionFactory.class)
public ReactiveRedisTemplate<Object, Object> reactiveRedisTemplate(ReactiveRedisConnectionFactory reactiveRedisConnectionFactory, ResourceLoader resourceLoader) {
    JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer(resourceLoader.getClassLoader());
    RedisSerializationContext<Object, Object> serializationContext = RedisSerializationContext.newSerializationContext().key(jdkSerializer).value(jdkSerializer).hashKey(jdkSerializer).hashValue(jdkSerializer).build();
    return new ReactiveRedisTemplate<>(reactiveRedisConnectionFactory, serializationContext);
}
Also used : ReactiveRedisTemplate(org.springframework.data.redis.core.ReactiveRedisTemplate) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project cas by apereo.

the class RedisObjectFactory method newRedisTemplate.

/**
 * New redis template.
 *
 * @param <K>               the type parameter
 * @param <V>               the type parameter
 * @param connectionFactory the connection factory
 * @return the redis template
 */
public static <K, V> CasRedisTemplate<K, V> newRedisTemplate(final RedisConnectionFactory connectionFactory) {
    val template = new DefaultCasRedisTemplate<K, V>();
    val string = new StringRedisSerializer();
    val jdk = new JdkSerializationRedisSerializer();
    template.setKeySerializer(string);
    template.setValueSerializer(jdk);
    template.setHashValueSerializer(jdk);
    template.setHashKeySerializer(string);
    template.setConnectionFactory(connectionFactory);
    return template;
}
Also used : lombok.val(lombok.val) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)

Aggregations

JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)18 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)14 Test (org.junit.Test)12 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)11 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)11 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)9 BeanFactory (org.springframework.beans.factory.BeanFactory)5 Date (java.util.Date)4 Bean (org.springframework.context.annotation.Bean)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 Message (org.springframework.messaging.Message)3 PollableChannel (org.springframework.messaging.PollableChannel)3 ErrorMessage (org.springframework.messaging.support.ErrorMessage)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ReactiveRedisTemplate (org.springframework.data.redis.core.ReactiveRedisTemplate)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 lombok.val (lombok.val)1 Ignore (org.junit.Ignore)1