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!
More Posts related to Java,- CRUD operations in Spring Boot + JDBC
- Java Check Leap Year - Programs with Code Examples
- [fix] Java JDBC ConnectException: Connection refused
- How to add hours and minutes to Java Instant
- Java Program: Random Number Generator
- Java: The value of the local variable string is not used
- How to get list of all Java versions installed on macOS
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Java + Spring JDBC Template + Gradle Example
- Convert String to LocalDate in Java
- Remove Trailing zeros BigDecimal Java
- Java 8 Predicate Functional Interface isEqual() Method Example
- How to Hardcode Date in Java with Examples
- Java 8: Predicate negate() default Function Example
- Java: Collect Stream as ArrayList or LinkedList
- The Motivation Behind Generics in Java Programming
- How to Add/Subtract Days to the Current Date in Java
- Error: Can not find the tag library descriptor for
- Setting up JUnit 5 dependency with Maven Example
- Run Java Code Every Second
- How to create a tar.gz file using Java
- [Fix] java: integer number too large compilation error
- Java 8: Find the Max value in a List
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- Convert Java Array to ArrayList Code Example
More Posts:- Resolve System.IO.PathTooLongException [Sharepoint C# .Net] - SharePoint
- Grep Alternative for Windows CMD or PowerShell: findstr - Windows
- What is macOS Ventura? - MacOS
- How to Stop Photos App from auto loading when device connected to the Mac - Mac-OS-X
- How to Change Mac Terminal Prompt - MacOS
- Cannot access files within Microsoft Teams - We are setting up your file directory - Teams
- [Android Studio] MainActivity does not exist - Android-Studio
- How to query database table names [MySQL/Oracle/SQL Server] - MySQL