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[]
}
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());
}
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;
}
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);
}
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;
}
Aggregations