Skip to content

Commit 3856722

Browse files
Added redis cache support common-data service
1 parent 5136bd7 commit 3856722

27 files changed

+237
-219
lines changed

client/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"semantic-ui-css": "^2.4.1",
3232
"stripe": "^8.78.0",
3333
"styled-components": "^5.1.1",
34-
"swiper": "^5.4.2"
34+
"swiper": "^5.4.2",
35+
"semantic-ui-react": "^0.88.2"
3536
},
3637
"scripts": {
3738
"start": "react-scripts start",
@@ -57,7 +58,7 @@
5758
]
5859
},
5960
"devDependencies": {
60-
"dotenv": "^8.2.0",
61-
"semantic-ui-react": "^0.88.2"
61+
"@testing-library/jest-dom": "^5.11.2",
62+
"@testing-library/react": "^10.4.7"
6263
}
6364
}

client/src/actions/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ export const sendPaymentToken = (token) => async dispatch => {
117117
axios(config)
118118
.then(function (response) {
119119
console.log(JSON.stringify(response.data));
120-
let paymentResponse = {...response.data,
120+
let paymentResponse = {
121+
...response.data,
121122
last4: token.card.last4, exp_year: token.card.exp_year,
122-
exp_month: token.card.exp_month, brand: token.card.brand}
123+
exp_month: token.card.exp_month, brand: token.card.brand
124+
}
123125

124126
if (paymentResponse.payment_failed) {
125127
history.push(`/checkout/cancel-payment/${response.data.charge_id}`)
@@ -174,10 +176,10 @@ export const getDataViaAPI = (type, uri) => async dispatch => {
174176
type: type, payload:
175177
{isLoading: false, data: JSON.parse(JSON.stringify(response.data))}
176178
});
177-
if (LOAD_FILTER_PRODUCTS.localeCompare(type) === 0) {
178-
if (window.location.search.localeCompare(uri.split("/products")[1]) !== 0) {
179-
history.push(uri)
180-
}
179+
180+
if (LOAD_FILTER_PRODUCTS.localeCompare(type) === 0 &&
181+
window.location.search.localeCompare(uri.split("/products")[1]) !== 0) {
182+
history.push(uri)
181183
}
182184
} else {
183185
dispatch({type: type, payload: {isLoading: false, statusCode: BAD_REQUEST_ERROR_CODE}});

docker-compose.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ services:
1616
networks:
1717
- spring-cloud-microservices
1818

19+
redis-cache:
20+
image: redis:latest
21+
container_name: redis-cache-container
22+
command: redis-server --requirepass ${REDIS_PASSWORD}
23+
ports:
24+
- 6379:6379
25+
networks:
26+
- spring-cloud-microservices
27+
1928
common-data-service:
2029
build:
2130
context: .
@@ -24,15 +33,19 @@ services:
2433
restart: always
2534
depends_on:
2635
- mysql-db
36+
- redis-cache
2737
- react-ui
2838
environment:
29-
- DB_HOST=${DB_HOST}
39+
- DB_HOST=mysql-db
3040
- DB_PORT=${DB_PORT}
3141
- DB_USER=${DB_USER}
3242
- DB_PASS=${DB_PASS}
3343
- DB_SCHEMA=${DB_SCHEMA}
3444
- ACTIVE_PROFILE=${ACTIVE_PROFILE}
3545
- COMMON_DATA_SERVICE_PORT=${COMMON_DATA_SERVICE_PORT}
46+
- REDIS_PASSWORD=${REDIS_PASSWORD}
47+
- REDIS_HOST=redis-cache
48+
- REDIS_PORT=${REDIS_PORT}
3649
links:
3750
- mysql-db:mysql
3851
expose:
@@ -50,9 +63,9 @@ services:
5063
stdin_open: true
5164
restart: always
5265
expose:
53-
- ${REACTT_APP_PORT}
66+
- ${REACT_APP_PORT}
5467
ports:
55-
- ${REACTT_APP_PORT}:${REACTT_APP_PORT}
68+
- ${REACT_APP_PORT}:${REACT_APP_PORT}
5669
environment:
5770
- REACT_APP_STRIPE_PUBLISH_KEY=${REACT_APP_STRIPE_PUBLISH_KEY}
5871
- REACT_APP_COMMON_DATA_SERVICE_IP=${REACT_APP_COMMON_DATA_SERVICE_IP}
@@ -62,6 +75,7 @@ services:
6275
- /usr/src/app/node_modules
6376
depends_on:
6477
- mysql-db
78+
- redis-cache
6579
networks:
6680
- spring-cloud-microservices
6781
networks:

server/common-data-service/pom.xml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,29 @@
6161
<version>1.2</version>
6262
</dependency>
6363

64+
<!-- <dependency>-->
65+
<!-- <groupId>com.cloudinary</groupId>-->
66+
<!-- <artifactId>cloudinary-http44</artifactId>-->
67+
<!-- <version>1.26.0</version>-->
68+
<!-- </dependency>-->
69+
70+
<!-- <dependency>-->
71+
<!-- <groupId>com.cloudinary</groupId>-->
72+
<!-- <artifactId>cloudinary-taglib</artifactId>-->
73+
<!-- <version>1.0.14</version>-->
74+
<!-- </dependency>-->
75+
6476
<dependency>
65-
<groupId>com.cloudinary</groupId>
66-
<artifactId>cloudinary-http44</artifactId>
67-
<version>1.26.0</version>
77+
<groupId>org.springframework.data</groupId>
78+
<artifactId>spring-data-redis</artifactId>
79+
<version>2.2.6.RELEASE</version>
6880
</dependency>
6981

7082
<dependency>
71-
<groupId>com.cloudinary</groupId>
72-
<artifactId>cloudinary-taglib</artifactId>
73-
<version>1.0.14</version>
83+
<groupId>redis.clients</groupId>
84+
<artifactId>jedis</artifactId>
85+
<version>3.1.0</version>
86+
<type>jar</type>
7487
</dependency>
7588

7689
<dependency>
@@ -84,7 +97,13 @@
8497
</exclusion>
8598
</exclusions>
8699
</dependency>
87-
</dependencies>
100+
<dependency>
101+
<groupId>com.vaadin.external.google</groupId>
102+
<artifactId>android-json</artifactId>
103+
<version>0.0.20131108.vaadin1</version>
104+
<scope>compile</scope>
105+
</dependency>
106+
</dependencies>
88107

89108
<build>
90109
<finalName>common-data-service</finalName>

server/common-data-service/src/main/java/com/ujjaval/ecommerce/commondataservice/CommonDataServiceApplication.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cache.annotation.EnableCaching;
56

67
@SpringBootApplication
8+
@EnableCaching
79
public class CommonDataServiceApplication {
810

9-
public static void main(String[] args) {
10-
SpringApplication.run(CommonDataServiceApplication.class, args);
11-
}
11+
public static void main(String[] args) {
12+
SpringApplication.run(CommonDataServiceApplication.class, args);
13+
}
1214
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@Configuration
99
@EnableWebMvc
10-
public class CorsConfigurer implements WebMvcConfigurer
10+
public class CorsConfig implements WebMvcConfigurer
1111
{
1212
@Override
1313
public void addCorsMappings(CorsRegistry registry) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.ujjaval.ecommerce.commondataservice.config;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.core.env.Environment;
7+
import org.springframework.data.redis.connection.RedisPassword;
8+
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
9+
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
10+
import org.springframework.data.redis.core.RedisTemplate;
11+
12+
import java.util.Objects;
13+
14+
@Configuration
15+
public class RedisConfig {
16+
17+
@Autowired
18+
Environment environment;
19+
20+
@Bean
21+
JedisConnectionFactory jedisConnectionFactory() {
22+
RedisStandaloneConfiguration redisStandaloneConfiguration =
23+
new RedisStandaloneConfiguration(Objects.requireNonNull(environment.getProperty("REDIS_HOST")),
24+
Integer.parseInt(Objects.requireNonNull(environment.getProperty("REDIS_PORT"))));
25+
26+
redisStandaloneConfiguration.
27+
setPassword(RedisPassword.of(Objects.requireNonNull(environment.getProperty("REDIS_PASSWORD"))));
28+
return new JedisConnectionFactory(redisStandaloneConfiguration);
29+
}
30+
31+
@Bean
32+
public RedisTemplate<String, Object> redisTemplate() {
33+
RedisTemplate<String, Object> template = new RedisTemplate<>();
34+
template.setConnectionFactory(jedisConnectionFactory());
35+
return template;
36+
}
37+
}

0 commit comments

Comments
 (0)