2

I want to implement real-time applications with Redis.

There are data that are pushed in real time on Redis, like the source code below that used lettuce library.

RedisClient redisClient = RedisClient.create(uri);
StatefulRedisConnection<String, String> connection = redisClient.connect() 

RedisStringAsyncCommands<String, String> asyncCommands = connection.async();
List<RedisFuture<?>> futures = Lists.newArrayList(); 

while(true) {
    futures.add(asyncCommands.set("key", "value"));
}

If I want to check the data at client in real time, how can I implement it?
At first time, I used pub/sub way, but the pub/sub method could not get the stored data.
It was just publish data - channel - subscribe data in real time.

For example, Kafka can continuously get data through the consumer, like that.

while(true) {
    ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
    for (ConsumerRecord<String, String> record : records) {
        logger.info("offset = {}, value = {}", record.offset(), record.value());
    }
}

Are there some ways?

aruighrha
  • 69
  • 6

0 Answers0