@Bean //TODO: replace with ReactiveStringRedisTemplate in future public ReactiveRedisTemplate<String, String> stringReactiveRedisTemplate( ReactiveRedisConnectionFactory reactiveRedisConnectionFactory, ResourceLoader resourceLoader) { RedisSerializer<String> serializer = new StringRedisSerializer(); RedisSerializationContext<String , String> serializationContext = RedisSerializationContext .<String, String>newSerializationContext() .key(serializer) .value(serializer) .hashKey(serializer) .hashValue(serializer) .build(); return new ReactiveRedisTemplate<>(reactiveRedisConnectionFactory, serializationContext); }
@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[] }
@Bean public ReactiveRedisTemplate<String, Post> reactiveJsonPostRedisTemplate( ReactiveRedisConnectionFactory connectionFactory) { RedisSerializationContext<String, Post> serializationContext = RedisSerializationContext .<String, Post>newSerializationContext(new StringRedisSerializer()) .hashKey(new StringRedisSerializer()) .hashValue(new Jackson2JsonRedisSerializer<>(Post.class)) .build(); return new ReactiveRedisTemplate<>(connectionFactory, serializationContext); }
private ReactiveRedisTemplate<String, Object> createReactiveRedisTemplate() { RedisSerializer<String> keySerializer = new StringRedisSerializer(); RedisSerializer<Object> valueSerializer = new JdkSerializationRedisSerializer( this.classLoader); RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext .<String, Object>newSerializationContext(valueSerializer) .key(keySerializer).hashKey(keySerializer).build(); return new ReactiveRedisTemplate<>(this.redisConnectionFactory, serializationContext); }
@Bean public RedisRateLimiter redisRateLimiter(ReactiveRedisTemplate<String, String> redisTemplate, @Qualifier("redisRequestRateLimiterScript") RedisScript<List<Long>> redisScript) { return new RedisRateLimiter(redisTemplate, redisScript); }
public RedisRateLimiter(ReactiveRedisTemplate<String, String> redisTemplate, RedisScript<List<Long>> script) { this.redisTemplate = redisTemplate; this.script = script; }