Git Product home page Git Product logo

spring-redis-cache's Introduction

spring-redis-cache

Application showcasing simple write through cache implementation using spring-redis module and jedis client

@Cacheable(value = "product", key = "#productId")

@CachePut(value = "product", key = "#productId")

@CacheEvict(cacheNames="product", key="#productId")

Read more about :- https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/

image

Java Version

Used open-jdk version 17 (https://openjdk.org/projects/jdk/17/)

Redis Installation

https://redis.io/docs/getting-started/installation/

Upon successful redis installation and running standalone redis, you should be able to view below screenshot

Screenshot 2023-05-11 at 2 01 30 AM

Build Tool

We are using maven tool to build the project. You can download & install maven from official website (https://maven.apache.org/install.html)

Making the build

Download the source code using git ssh or https from https://github.com/souravkantha/spring-redis-cache

- [x] Check if maven is installed by putting 'mvn' command in command prompt or terminal

  • Go the root directory i.e; spring-redis-cache

  • Use command mvn clean package. After the build is successful, run the program using following command

    java -jar target/cache-1.0.jar

Upon successful start of the service, you should see the h2 database console

Open h2 console : http://localhost:8080/h2-console/login.jsp

Screenshot 2023-05-10 at 11 44 29 PM Screenshot 2023-05-10 at 11 56 25 PM

Test data added using data.sql (in resources directory)

INSERT INTO ITEMS VALUES (10000, 'Kelloggs Crunchy Granola Almonds and Cranberries', 'Kelloggs Crunchy Granola Almonds and Cranberries','Breakfast Cereal', 330, 1, 1);    
INSERT INTO ITEMS VALUES (10001, 'Kelloggs Crunchy Granola Chocolate & Almonds', 'Kelloggs Crunchy Granola Chocolate & Almonds', 'Breakfast Cereal', 350, 1, 1);    
INSERT INTO ITEMS VALUES (10002, 'Kelloggs muesli', 'Kelloggs muesli','Breakfast Cereal', 270, 1, 1);    
INSERT INTO ITEMS VALUES (10003, 'Kelloggs Chocos', 'Kelloggs Chocos','Breakfast Cereal', 350, 1, 1);    
INSERT INTO ITEMS VALUES (10004, 'Kelloggs Corn Flakes Real Almond Honey', 'Kelloggs Corn Flakes Real Almond Honey', 'Breakfast Cereal', 195, 1, 1); 

To test using curl

Create Product (using

curl --location --request POST 'http://localhost:8080/products' --header 'Content-Type: application/json' --data-raw '{"productId": 20000,"productName": "Kelloggs Crunchy Granola", "productDescription": "Kelloggs Crunchy Granola Almonds and Cranberries","type": "Breakfast Cereal","price": 330,"quantity": 1,"version": 1}'

Check with redis-cli after new product creation (cache is added for key product::20000)

Screenshot 2023-05-11 at 6 33 39 PM

Update Product

curl --location --request PATCH 'http://localhost:8080/products/20000' --header 'Content-Type: application/json' --data-raw '{"productId": 20000,"productName": "Kelloggs Crunchy Granola Almonds 1 Kg","productDescription": "Kelloggs Crunchy Granola Almonds and Cranberries","type":"Breakfast Cereals","price": 330,"quantity": 1,"version": 1}'

Get Product

curl --location --request GET 'http://localhost:8080/products/20000'

Delete Product

curl --location --request DELETE 'http://localhost:8080/products/20000'

Check with redis-cli after product deletion (cache is evicted for key product::20000)

Screenshot 2023-05-11 at 6 37 04 PM

spring-redis-cache's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.