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

The following examples show how to use org.springframework.data.redis.core.ReactiveStringRedisTemplate. 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 File: RedissonSubscribeReactiveTest.java    From redisson with 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 File: RedissonSubscribeReactiveTest.java    From redisson with 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 File: RedissonSubscribeReactiveTest.java    From redisson with 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 File: RedisReactiveInitializer.java    From spring-fu with 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
Source File: GatewayRedisAutoConfiguration.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@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 File: RedisRateLimiter.java    From spring-cloud-gateway with 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 File: RedisRateLimiter.java    From spring-cloud-gateway with 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
Source File: RedisRateLimiterUnitTests.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@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 File: HerokuRedisConfig.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
@Bean
ReactiveStringRedisTemplate template(ReactiveRedisConnectionFactory reactiveRedisConnectionFactory) {
	return new ReactiveStringRedisTemplate(reactiveRedisConnectionFactory);
}
 
Example #10
Source File: RedisConfig.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
@Bean
ReactiveStringRedisTemplate template(ReactiveRedisConnectionFactory reactiveRedisConnectionFactory) {
	return new ReactiveStringRedisTemplate(reactiveRedisConnectionFactory);
}
 
Example #11
Source File: RedisChatMessagePublisher.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
public RedisChatMessagePublisher(ReactiveStringRedisTemplate reactiveStringRedisTemplate, RedisAtomicInteger chatMessageCounter, RedisAtomicLong activeUserCounter, ObjectMapper objectMapper) {
	this.reactiveStringRedisTemplate = reactiveStringRedisTemplate;
	this.chatMessageCounter = chatMessageCounter;
	this.activeUserCounter = activeUserCounter;
	this.objectMapper = objectMapper;
}
 
Example #12
Source File: RedisChatMessageListener.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
public RedisChatMessageListener(ReactiveStringRedisTemplate reactiveStringRedisTemplate, ChatWebSocketHandler chatWebSocketHandler) {
	this.reactiveStringRedisTemplate = reactiveStringRedisTemplate;
	this.chatWebSocketHandler = chatWebSocketHandler;
}
 
Example #13
Source File: RedisRepository.java    From reactor-workshop with GNU General Public License v3.0 4 votes vote down vote up
public RedisRepository(ReactiveStringRedisTemplate redis) {
    this.redis = redis;
}