Redis Java client for Aiven Redis service
What is Aiven for Redis?
Redis is an open-source in-memory data structure store that has been widely used for applications such as NoSQL databases, caches, and message brokers. Given its versatility and lightning-fast speed, it’s no surprise that Redis has frequently earned the title of “most loved database” in StackOverflow’s developer survey.
While users can get started working with Redis out of the box, a number of cloud computing services also provide their own fully managed Redis offerings. These include Amazon Web Services’ MemoryDB for Redis and ElastiCache for Redis, as well as Google Cloud Memorystore for Redis.
Beyond the offerings from AWS and Google Cloud, there are a number of third-party independent cloud hosting solutions for Redis. One of the most popular is Aiven, which calls itself a “fully managed, open source cloud data platform” that “makes setting up cloud databases so simple anyone can do it.”
In particular, Aiven for Redis provides users with a fully managed, in-memory, highly performant Redis NoSQL database. Aiven handles concerns such as scalability, availability, and software upgrades, making it easy for customers to deploy and use their own Redis instance in the cloud.
Redis Java client for Aiven Redis service
Whether you’re using AWS, Google Cloud, or Aiven, hosting Redis in the cloud with a fully managed solution takes away much of the stress of supporting your own Redis deployment. However, there’s still one issue at stake: the base version of Redis doesn’t include support for programming languages such as Java.
Instead, Java developers can use third-party Redis Java frameworks such as Redisson. Redisson is a Redis Java client that implements dozens of the most common Java services, data structures, and other objects. This dramatically lowers the Redis learning curve for Java developers.
Redisson takes a vendor-agnostic approach when it comes to setting up a Redis instance. Using the addNodeAddress() function, Java developers can connect to the Redis cloud service of their choice, including Aiven. Below is an example piece of code that demonstrates how to connect to Aiven using Redisson:
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(); config.useReplicatedServers() .addNodeAddress("redis://redis.aiven.io:6379"); 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); redisson.shutdown(); } }
Note that this code snippet uses replicated mode, as indicated by the useReplicatedServers() function. In this mode, each node’s role is continuously polled to determine if a failover has occurred. If it has, a new master is selected to ensure that the Redis instance remains available.
Aiven for Redis hosting can support configurations such as master and slave nodes, as well as a single host bound to multiple slave nodes. This and other functionality is available in Redisson PRO, which offers additional features, blazing-fast performance, and 24/7 technical support.
Similar articles
- Redis Java client for Azure Cache
- Redis Java client for AWS ElastiCache
- Redis Java client with code example
- Redis Java client for AWS Redis Global Datastore
- Redis Java Client for Google Cloud Memorystore for Redis High Availability
- Redis Java client for Google Cloud Memorystore for Redis
- Redis Java Client for Amazon MemoryDB
- Redis Client Tracing in Java
- Redis Client Metrics in Java
- Redis Notifications in Java