This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
This article describes how to use Azure Redis as the HTTP session cache for WebSphere Liberty or Open Liberty.
In this guide, you'll:
This article is intended to help you quickly get to deployment. Before going to production, you should exploreTuning Liberty.
If you're interested in providing feedback or working closely on your migration scenarios with the engineering team developing WebSphere on Azure solutions, fill out this shortsurvey on WebSphere migration and include your contact information. The team of program managers, architects, and engineers will promptly get in touch with you to initiate close collaboration.
Azure Managed Redis provides an in-memory data store based on theRedis Enterprise software. Use the following steps to create an Azure Managed Redis instance, and then note down its connection information. You use this information later to configure the sample application.
Create an Azure Managed Redis instance by following the steps inQuickstart: Create an Azure Managed Redis Instance. Carefully note the following differences:
At step 3 of the sectionCreate a Redis instance, where you're on theBasics tab, select aCache SKU that supports Azure Managed Redis. For this guide, selectBalanced (For general purpose workloads with typical performance requirements). For more information, seeChoosing the right tier.
At step 4 of the sectionCreate a Redis instance, where you're on theNetworking tab, for theConnectivity option, selectPublic Endpoint. This option is the best choice for simplicity when using this guide. For production, you should consider usingPrivate Endpoint for better security.
At step 5 of the sectionCreate a Redis instance, where you're on theAdvanced tab, configure the following settings:
ForAuthentication, enableAccess Keys Authentication. This option is the best choice for simplicity when using this guide. For optimal security, we recommend using Microsoft Entra ID with managed identities to authorize requests against your cache, if possible. Authorization by using Microsoft Entra ID and managed identities provides superior security and ease of use over shared access key authorization. For more information about using managed identities with your cache, seeUse Microsoft Entra ID for cache authentication.
SetClustering policy toEnterprise for a nonclustered cache, which works for this guide where single node configuration is used. For more information, seeClustering on Enterprise.
After the deployment completes, selectGo to resource if you're on theDeployment page. Otherwise, navigate to the Azure portal, find, and select your Azure Managed Redis instance.
On theOverview page, note down theEndpoint value. You use this value in theREDIS_CACHE_ADDRESS environment variable later.
SelectSettings >Authentication. SelectAccess keys and note down thePrimary value. You use this value as theREDIS_CACHE_KEY environment variable later.
Use the following command to export the environment variablesREDIS_CACHE_ADDRESS andREDIS_CACHE_KEY:
export REDIS_CACHE_ADDRESS=rediss://<your-redis-cache-endpoint>export REDIS_CACHE_KEY=<your-primary-access-key>WebSphere Liberty and Open Liberty provide a session cache feature that enables you to store HTTP session data in an external cache. In this guide, you use theJCache Session Persistence feature to store the session data in the Azure Managed Redis instance.
Use the following commands to clone the sample code for this guide. The sample is in theopen-liberty-on-aks repository on GitHub. There are a few samples in the repository. This article usesjava-app-jcache.
git clone https://github.com/Azure-Samples/open-liberty-on-aks.gitcd open-liberty-on-aksgit checkout 20250228cd java-app-jcacheIf you see a message about being indetached HEAD state, this message is safe to ignore. It just means you checked out a tag.
The application has the following file structure:
java-app-jcache/├── pom.xml├── pom-redisson.xml└── src └── main ├── docker │ ├── Dockerfile │ └── Dockerfile-wlp ├── java ├── liberty │ └── config │ └── server.xml ├── redisson │ └── redisson-config.yaml ├── resources └── webappThepom.xml file is the Maven project file that contains the dependencies and plugins for the sample application.
Thepom-redisson.xml file is used to copy dependencies for the Redisson client library to the shared resources directory of the Liberty server later.
Thejava,resources, andwebapp directories contain the source code of the sample application.
In theliberty/config directory, theserver.xml file is used to configure the HTTP session cache for Open Liberty and WebSphere Liberty.
In theredisson directory, theredisson-config.yaml file is used to configure the connection to the Azure Managed Redis instance.
Thedocker directory contains two Dockerfiles.Dockerfile is used to build an image with Open Liberty andDockerfile-wlp is used to build an image with WebSphere Liberty.
Use the following steps to build and run your sample application locally. These steps use Maven and theliberty-maven-plugin. For more information about theliberty-maven-plugin, seeBuilding a web application with Maven.
Verify the current working directory isjava-app-jcache in your local clone.
Run the Maven commandmvn clean package and package the application.
Runmvn -Predisson validate to copy the Redisson configuration file to the correct target location. This step also inserts the values of the environment variablesREDIS_CACHE_ADDRESS andREDIS_CACHE_KEY into theredisson-config.yaml file, which is referenced by theserver.xml file.
Runmvn dependency:copy-dependencies -f pom-redisson.xml -DoutputDirectory=target/liberty/wlp/usr/shared/resources to copy the Redisson client library and its dependencies to the shared resources directory of the Liberty server.
Run the Maven commandmvn liberty:dev and start the application. If the application is successfully started, you should seeThe defaultServer server is ready to run a smarter planet. in the command output.
You should see output similar to the following if the Redis connection is successful.
[INFO] [err] [Default Executor-thread-3] INFO org.redisson.Version - Redisson 3.23.4[INFO] [err] [redisson-netty-2-7] INFO org.redisson.connection.pool.MasterPubSubConnectionPool - 1 connections initialized for redacted.<region>.redis.azure.net/<ip_address>:10000[INFO] [err] [redisson-netty-2-20] INFO org.redisson.connection.pool.MasterConnectionPool - 24 connections initialized for redacted.<region>.redis.azure.net/<ip_address>:10000Open a web browser tohttp://localhost:9080 and you should see the application home page.

In theNew coffee form, set values for the fieldsName andPrice, and then selectSubmit. The application creates a new coffee, persists it, and also stores the HTTP session in the Azure Managed Redis instance.
After a few seconds, you see the new coffee displayed in the tableOur coffees.

To demonstrate that the session data can be retrieved from Redis, useCtrl+C to stop the application and restart it with themvn liberty:dev command.
Then, refresh the application home page. You should see the same session data displayed in the sectionNew coffee. Stop the application when you're done testing.
Optionally, you can package and run the application in a container by using the following steps. The sample application provides two Dockerfiles for Open Liberty and WebSphere Liberty. This guide uses the Dockerfile for Open Liberty, but you can use the Dockerfile for WebSphere Liberty by following similar steps.
Install Docker for your OS. For more information, seeGet Docker.
Use the following command to build the Docker image:
docker build -t javaee-cafe-jcache:v1 -f src/main/docker/Dockerfile .Use the following command to start the Docker container:
docker run -it --rm \ -p 9080:9080 \ -e REDIS_CACHE_ADDRESS=${REDIS_CACHE_ADDRESS} \ -e REDIS_CACHE_KEY=${REDIS_CACHE_KEY} \ --mount type=bind,source=$(pwd)/target/liberty/wlp/usr/servers/defaultServer/redisson-config.yaml,target=/config/redisson-config.yaml \ javaee-cafe-jcache:v1After the container starts, you can test it by using steps similar to the ones you use to run the application locally without Docker.
To avoid Azure charges, you should clean up unnecessary resources. When the Azure Managed Redis instance is no longer needed, find its resource group name and delete it from the Azure portal.
For more information, seeDelete resource groups.
You can learn more from references used in this guide:
If you want to deploy the sample application to Azure, reference the following articles:
To explore options to run WebSphere products on Azure, seeWhat are solutions to run the WebSphere family of products on Azure?
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?