Redis Java client for Azure Cache

Published on
September 28, 2022
What is Azure Cache for Redis?

Redis is one of the most popular software projects for storing data structures in-memory. Microsoft's Azure Cache for Redis is a "fully managed, open source-compatible in-memory data store" for use with Redis that is available via the Microsoft Azure cloud computing platform. Azure Cache for Redis combines the rich feature set of Redis with the stability and support of Microsoft's cloud platform.

As a fully managed Redis solution, Azure Cache for Redis includes built-in features for performance, scalability, and security. This makes it a highly convenient option for users of Azure's cloud computing services who want to get up and running with Redis right away. Users can configure Azure Cache for Redis to automatically create and manage instances of Redis as needed, while enjoying all of the same features as the original Redis solution.

Microsoft is retiring Azure Cache for Redis in favour of Azure Managed Redis, which runs Redis Enterprise. The Enterprise and Enterprise Flash tiers retire on 31 March 2027, and the Basic, Standard and Premium tiers on 30 September 2028. Azure has no first-party managed Valkey service. If you want Valkey on Azure, see which companies offer Valkey support for the third-party and self-managed options.

If the same application also sends messages through Azure Service Bus, Redisson PRO can run those queues and topics on the Redis instance you already have. We compare the two, including what you give up, in Azure Service Bus vs Reliable Queue and PubSub.

Redisson: a Redis Java client for Azure Cache

Many Redis users want to combine it with the Java programming language; however, Redis doesn't include support for Java out of the box. To integrate Redis with Java, you can rely on a third-party Redis Java client such as Redisson.

Redisson is a thread-safe Redis Java client library that takes advantage of many of the core principles of the Java programming language. It includes support for all of the most popular Java data structures and collections: Lists, Maps, Queues, Locks, Semaphores, and much more.

The original Redis API can be difficult to learn for newcomers, with more than 400 different commands to worry about. However, the same isn't true for Redisson. Thanks to Redisson's use of all the familiar concepts and interfaces in Java, you can get started with the Redisson library immediately without a learning curve.

To get a sense for just how easy it is to begin using Redisson, see the example code below:


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.useSingleServer()
              .setAddress("redis://test.redis.cache.windows.net:6379");
        
        RedissonClient redisson = Redisson.create(config);
        
        // perform operations
        
        RBucket<String> bucket = redisson.getBucket("simpleObject");
        bucket.set("This is object value");

        RMap<String, String> 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();
    }
}

As you can see in the example above, Redisson is capable of using familiar Java interfaces such as RBucket and RMap in a distributed and concurrent implementation. RMap extends the original Map interface in Java, while RBucket provides a universal container and API for working with any type of object.

Redisson comes in two editions that can fit the needs of every business:

  • The open-source Redisson project includes support for distributed objects, collections, locks, synchronizers, and services. It also includes Asynchronous, Reactive Streams, and RxJava2 APIs and integrates with popular frameworks such as Spring Cache, Hibernate Cache, and Tomcat Session Manager.
  • Redisson PRO edition includes all of the functionality of the open-source version, as well as additional features to improve ease of use and performance. When compared with open-source Redisson in a benchmark environment, Redisson PRO exhibited significantly better throughput and lower execution times.

Use Redis commands mapping table to find Redisson method for a particular Redis command.

Similar articles