Redis Java client for AWS Redis Global Datastore

What is AWS Redis Global Datastore?

Amazon Web Services is one of the leading public cloud providers. It’s therefore no surprise that AWS includes support for Redis, an open-source in-memory data structure store with use cases including databases, caches, and message brokers. Specifically, AWS provides the Amazon ElastiCache for Redis service, a fully managed solution that helps users set up and manage Redis in-memory data stores.

Global Datastore is a feature of Amazon ElastiCache for Redis that improves reliability and availability by replicating data across different regions. With Global Datastore, users can write to their Amazon ElastiCache for Redis instance in one AWS region, and then have this data available in two other cross-region replica clusters. The Global Datastore feature helps support real-time AWS applications that require low latency and high availability.

Redis Java client for AWS Redis Global Datastore

Redis is a tremendously useful solution for many applications, but there’s one issue: it doesn’t come with out-of-the-box support for the Java programming language. The good news is that Java developers can still work with Redis by using a Redis Java client such as Redisson.

Redisson is an open-source Redis-based framework that provides a wrapper and interface for working with Redis in Java. Redisson offers dozens of familiar Java constructs, classes, objects, interfaces, and services, making it easy for developers to get started and bridge the gap between Redis and Java.

In particular, Redisson includes support for AWS Redis Global Datastore. Below is a simple code example of how to use Redisson with AWS Redis Global Datastore:

package redis.demo;

import org.redisson.Redisson;

import org.redisson.api.RBucket;

import org.redisson.api.RedissonClient;

public class Application {

    public static void main(String[] args) {
        Config config = new Config();
              .addAddress("redis://cluster1:32414", "redis://cluster2:32411");       

        RedissonClient redisson = Redisson.create(config);

        // perform operations
        RBucket bucket = redisson.getBucket("simpleObject");
        bucket.set("This is object value");
        RMap map = redisson.getMap("simpleMap");
        map.put("mapKey", "This is map value");
        String objectValue = bucket.get();
        System.out.println("stored object value: " + objectValue);
        String mapValue = map.get("mapKey");
        System.out.println("stored map value: " + mapValue);


The Redisson PRO edition includes all of the functionality of open-source Redisson, as well as additional features and performance that developers need for high-powered Redis Java software. Redisson PRO supports multiple cluster setups with an active-passive data replication relationship and is compatible with AWS Redis Global Datastore.

The multi-cluster connection mode is available with the following line of Java code:

ClusterServersConfig clusterConfig = config.useMultiClusterServers();

Developers can specify a number of settings for the ClusterServersConfig object, including:

  • addresses: The Redis cluster setup, which is defined by the Redis hostname of any of the nodes in the cluster or the Redis endpoint.

  • scanInterval: The number of milliseconds between scans of the Redis cluster topology and the primary and secondary clusters.

  • readMode: The node type used for read operations. The available values are SLAVE (read from slave nodes), MASTER (read from master nodes), and MASTER_SLAVE (read from both).

  • datastoreMode: The mode used for the Redis data store. The available values are ACTIVE (only using the primary cluster) and ACTIVE_PASSIVE (using the primary cluster for read/write operations, and using the secondary clusters for read operations only).

Similar articles