If you are looking to work on a String Boot + Redis Cloud Database project and looking for ways to set it up! well, in this tutorial, I will quickly show you how do that with a simple "Hello Redis Cloud!" project.
Step 1: Go to https://start.spring.io/ and create your project. Make sure to add Spring Data Redis (Access+Driver) NOSQL dependency.
Make sure that you have added the dependencies correctly.
build.gradle
dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-redis' }
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
- Step 2: As we are using Redis Cloud Database, I assume you have setup your account on redis.com. Login to your Redis Cloud Console and get the Public endpoint of your database and the password.
- Step 3: Open your application.properties file and add the below property,
spring.data.redis.url=redis://default:your-db-password@redis-host..cloud.redislabs.com:your-db-port
Note: Fill in your password, host:port, username remains default.
- Step 4: Now to test if your connection to the Redis Cloud Database is working good we will write some basic "Hello Redis Cloud!" code by modifying the class that has our main method with annotation @RedisdemoApplication.
package com.example.redisdemo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.redis.core.RedisTemplate; //Example by Code2care.org @SpringBootApplication public class RedisdemoApplication implements ApplicationRunner { @Autowired public RedisTemplate redisTemplate; public static void main(String[] args) { SpringApplication.run(RedisdemoApplication.class, args); } @Override public void run(ApplicationArguments args) throws Exception { redisTemplate.opsForValue().set("message", "Hello Redis!"); System.out.println(redisTemplate.opsForValue().get("message")); } }
Step 5: Thats it! We are all good to run our first Spring Boot + Redis Cloud Db example!
Hope you found this tutorial useful! If yes, do write in a comment, if not, I am happy to help with the problems you are facing.
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to Java,- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
More Posts:- How to get query string in JavaScript HTML location.search - JavaScript
- PowerShell: The term Connect-AzureAD is not recognized as the name of a cmdlet - Powershell
- How to Run PowerShell Script as a Windows Scheduler Task - Powershell
- Android Eclipse This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in - Android
- How to determine Gradle Version in Android Studio - Android-Studio
- Visual Studio Code available for Apple Mac ARM64 build for native M1 processor support - Microsoft
- How to restore closed file in Notepad++ - NotepadPlusPlus
- Unable to connect to the Internet : Google Chrome - Chrome