Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
page_type languages name description products
sample
java
Quickstart: Use Azure Cache for Redis in Java
Learn how to incorporate Azure Cache for Redis into a Java app using the Jedis Redis client.
azure
azure-cache-redis

Quickstart: Use Azure Cache for Redis in Java

This sample show you how to incorporate Azure Cache for Redis into a Java app using the Jedis Redis client. See the accompanying article on the documentation site for details, including best practices and how to create the sample code from scratch.

Prerequisites

Set up the working environment

Depending on your operating system, add environment variables for your cache's Host name and Primary access key. Open a command prompt, or a terminal window, and set up the following values:

set REDISCACHEHOSTNAME=<YOUR_HOST_NAME>.redis.cache.windows.net
set REDISCACHEKEY=<YOUR_PRIMARY_ACCESS_KEY>
export REDISCACHEHOSTNAME=<YOUR_HOST_NAME>.redis.cache.windows.net
export REDISCACHEKEY=<YOUR_PRIMARY_ACCESS_KEY>
$env:REDISCACHEHOSTNAME = '<YOUR_HOST_NAME>.redis.cache.windows.net'
$env:REDISCACHEKEY = '<YOUR_PRIMARY_ACCESS_KEY>'

Replace the placeholders with the following values:

  • <YOUR_HOST_NAME>: The DNS host name, obtained from the Properties section of your Azure Cache for Redis resource in the Azure portal.
  • <YOUR_PRIMARY_ACCESS_KEY>: The primary access key, obtained from the Access keys section of your Azure Cache for Redis resource in the Azure portal.

Run the sample

Download the sample code to your development PC.

Change directories to the folder containing this sample.

Execute the following Maven command to build and run the app:

mvn compile
mvn exec:java -D exec.mainClass=example.demo.App

References