Redis Cache libraries for Java

Overview

Azure Redis Cache is a secure, distributed key-value store based on the popular open source Redis cache.

To get started with Azure Redis Cache, see How to use Azure Redis Cache with Java.

Client library

Connect to Azure Redis Cache and store and retrieve values from the cache using the open-source Jedis client.

Add a dependency to your Maven pom.xml file to use the client library in your project.

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
    <type>jar</type>
</dependency>

Example

Connect to Azure Redis and insert a string into the cache.

JedisShardInfo shardInfo = new JedisShardInfo("<name>.redis.cache.windows.net", 6380, useSsl);
    shardInfo.setPassword("<key>"); /* Use your access key. */
    Jedis jedis = new Jedis(shardInfo);
    jedis.set("foo", "bar");

Management API

Create and scale Azure Redis resources and manage access keys to with the management API.

Add a dependency to your Maven pom.xml file to use the resource management libraries in your project.

<dependency>
   <groupId>com.azure.resourcemanager</groupId>
   <artifactId>azure-resourcemanager</artifactId>
   <version>2.1.0</version>
</dependency>

For detailed information on how to use the Java resource management libraries, please refer to this doc

Example

Create a new Azure Redis Cache in the two-node standard tier.

RedisCache cache = azure.redisCaches().define(redisCacheName)
    .withRegion(Region.US_CENTRAL)
    .withNewResourceGroup(rgName)
    .withStandardSku();

Samples

Manage Azure Redis Cache

Explore more sample Java code for Azure Redis Cache you can use in your apps.