Skip to content

Spring Boot App connecting to Redis Database for CRUD operations

Notifications You must be signed in to change notification settings

dineschandgr/SpringBoot_RedisDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringBoot_RedisDB

Spring Boot App connecting to Redis Database for CRUD operations

Redis is used as a database for CRUD operations in this application

#Preqequisites

  1. Download and install Redis in local machine
  2. After unzipping the redis jar, open redis-server.exe file to start the redis server. Redis runs on port 6379 on localhost
  3. Then start the redis-cli.exe to open the client

There are 2 types of Java Redis clients namely

  1. Jedis (Synchronous and single threaded. Easy to use)
  2. Lettuce ( uses asynchronous and reactive API. Multithreaded. difficult to use)

#Replication

  • Redis Sentinel provides high availability for Redis
  • Uses Master Slave concept.
  • Only master can take writes

#MessageBroker

  • Redis can also be used as Message Broker with Publish and Subscribe

#Steps

  1. Create a Jedis Connection Fcatory and set it to the RedisTemplate
  2. Provide redis configuration in application.properties file
  3. Use hashOperations provided by Spring Boot in the Repository
  4. Use HashOperations to perform the CRUD operation
  5. Go to postman and enter the url http:https://localhost:8080/redis/addUser and enter the payload for the post method
  6. For update, use http:https://localhost:8080/redis/update with the payload
  7. FindAll users, http:https://localhost:8080/redis/findAll
  8. Get a user, http:https://localhost:8080/redis/getUser/1
  9. Delete a user, http:https://localhost:8080/redis/delete/1

#Verify

  1. Check the redis-cli with the command keys *
  2. Open another cli with the command monitor
  3. This cli will display all the operations done in the redis server

About

Spring Boot App connecting to Redis Database for CRUD operations

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published