Java Code Examples for org.springframework.data.redis.core.ReactiveStringRedisTemplate

The following examples show how to use org.springframework.data.redis.core.ReactiveStringRedisTemplate. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: redisson   Source File: RedissonSubscribeReactiveTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTemplate() {
    RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
    AtomicLong counter = new AtomicLong();

    ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
    template.listenTo(ChannelTopic.of("test")).flatMap(message -> {
        counter.incrementAndGet();
        return Mono.empty();
    }).subscribe();

    template.listenTo(ChannelTopic.of("test2")).flatMap(message -> {
        counter.incrementAndGet();
        return Mono.empty();
    }).subscribe();

    ReactiveRedisConnection connection = factory.getReactiveConnection();
    connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();

    Awaitility.await().atMost(Duration.ONE_SECOND)
                .until(() -> counter.get() == 1);
}
 
Example 2
Source Project: redisson   Source File: RedissonSubscribeReactiveTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTemplate() {
    RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
    AtomicReference<byte[]> msg = new AtomicReference<byte[]>();

    ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
    template.listenTo(ChannelTopic.of("test")).flatMap(message -> {
        msg.set(message.getMessage().getBytes());
        return template.delete("myobj");
    }).subscribe();

    ReactiveRedisConnection connection = factory.getReactiveConnection();
    connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();

    Awaitility.await().atMost(Duration.ONE_SECOND)
                .until(() -> Arrays.equals("msg".getBytes(), msg.get()));
}
 
Example 3
Source Project: redisson   Source File: RedissonSubscribeReactiveTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTemplate() {
    RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
    AtomicLong counter = new AtomicLong();

    ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
    template.listenTo(ChannelTopic.of("test")).flatMap(message -> {
        counter.incrementAndGet();
        return Mono.empty();
    }).subscribe();

    template.listenTo(ChannelTopic.of("test2")).flatMap(message -> {
        counter.incrementAndGet();
        return Mono.empty();
    }).subscribe();

    ReactiveRedisConnection connection = factory.getReactiveConnection();
    connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();

    Awaitility.await().atMost(Duration.ONE_SECOND)
                .until(() -> counter.get() == 1);
}
 
Example 4
Source Project: spring-fu   Source File: RedisReactiveInitializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
  public void initialize(GenericApplicationContext context) {
RedisReactiveAutoConfiguration redisAutoConfiguration = new RedisReactiveAutoConfiguration();
context.registerBean("reactiveRedisTemplate", ReactiveRedisTemplate.class,
		() -> redisAutoConfiguration.reactiveRedisTemplate(context.getBean(ReactiveRedisConnectionFactory.class), context),
		(definition) -> ((RootBeanDefinition) definition).setTargetType(ResolvableType.forClassWithGenerics(ReactiveRedisTemplate.class, Object.class, Object.class)));
context.registerBean("reactiveStringRedisTemplate", ReactiveStringRedisTemplate.class,
		() -> redisAutoConfiguration.reactiveStringRedisTemplate(context.getBean(ReactiveRedisConnectionFactory.class)));
  }
 
Example 5
@Bean
@ConditionalOnMissingBean
public RedisRateLimiter redisRateLimiter(ReactiveStringRedisTemplate redisTemplate,
		@Qualifier(RedisRateLimiter.REDIS_SCRIPT_NAME) RedisScript<List<Long>> redisScript,
		ConfigurationService configurationService) {
	return new RedisRateLimiter(redisTemplate, redisScript, configurationService);
}
 
Example 6
Source Project: spring-cloud-gateway   Source File: RedisRateLimiter.java    License: Apache License 2.0 5 votes vote down vote up
public RedisRateLimiter(ReactiveStringRedisTemplate redisTemplate,
		RedisScript<List<Long>> script, ConfigurationService configurationService) {
	super(Config.class, CONFIGURATION_PROPERTY_NAME, configurationService);
	this.redisTemplate = redisTemplate;
	this.script = script;
	this.initialized.compareAndSet(false, true);
}
 
Example 7
Source Project: spring-cloud-gateway   Source File: RedisRateLimiter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Used when setting default configuration in constructor.
 * @param context the ApplicationContext object to be used by this object
 * @throws BeansException if thrown by application context methods
 */
@Override
@SuppressWarnings("unchecked")
public void setApplicationContext(ApplicationContext context) throws BeansException {
	if (initialized.compareAndSet(false, true)) {
		if (this.redisTemplate == null) {
			this.redisTemplate = context.getBean(ReactiveStringRedisTemplate.class);
		}
		this.script = context.getBean(REDIS_SCRIPT_NAME, RedisScript.class);
		if (context.getBeanNamesForType(ConfigurationService.class).length > 0) {
			setConfigurationService(context.getBean(ConfigurationService.class));
		}
	}
}
 
Example 8
@Before
public void setUp() {
	when(applicationContext.getBean(ReactiveStringRedisTemplate.class))
			.thenReturn(redisTemplate);
	when(applicationContext.getBeanNamesForType(ConfigurationService.class))
			.thenReturn(CONFIGURATION_SERVICE_BEANS);
	redisRateLimiter = new RedisRateLimiter(DEFAULT_REPLENISH_RATE,
			DEFAULT_BURST_CAPACITY);
}
 
Example 9
Source Project: spring-redis-websocket   Source File: HerokuRedisConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
ReactiveStringRedisTemplate template(ReactiveRedisConnectionFactory reactiveRedisConnectionFactory) {
	return new ReactiveStringRedisTemplate(reactiveRedisConnectionFactory);
}
 
Example 10
Source Project: spring-redis-websocket   Source File: RedisConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
ReactiveStringRedisTemplate template(ReactiveRedisConnectionFactory reactiveRedisConnectionFactory) {
	return new ReactiveStringRedisTemplate(reactiveRedisConnectionFactory);
}
 
Example 11
public RedisChatMessagePublisher(ReactiveStringRedisTemplate reactiveStringRedisTemplate, RedisAtomicInteger chatMessageCounter, RedisAtomicLong activeUserCounter, ObjectMapper objectMapper) {
	this.reactiveStringRedisTemplate = reactiveStringRedisTemplate;
	this.chatMessageCounter = chatMessageCounter;
	this.activeUserCounter = activeUserCounter;
	this.objectMapper = objectMapper;
}
 
Example 12
public RedisChatMessageListener(ReactiveStringRedisTemplate reactiveStringRedisTemplate, ChatWebSocketHandler chatWebSocketHandler) {
	this.reactiveStringRedisTemplate = reactiveStringRedisTemplate;
	this.chatWebSocketHandler = chatWebSocketHandler;
}
 
Example 13
public RedisRepository(ReactiveStringRedisTemplate redis) {
    this.redis = redis;
}