Skip to content

Commit 106bfd5

Browse files
committed
Add Redis config
1 parent d172096 commit 106bfd5

File tree

10 files changed

+66
-81
lines changed

10 files changed

+66
-81
lines changed

pom.xml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
<properties>
1818
<java.version>11</java.version>
19-
<hazelcast.version>4.0</hazelcast.version>
20-
<hazelcast-hibernate53.version>2.0.0</hazelcast-hibernate53.version>
21-
<hazelcast-client.version>3.12.6</hazelcast-client.version>
19+
<redisson-hibernate-53.version>3.12.1</redisson-hibernate-53.version>
2220
</properties>
2321

2422
<dependencies>
@@ -38,19 +36,17 @@
3836
<groupId>org.springframework.boot</groupId>
3937
<artifactId>spring-boot-starter-web</artifactId>
4038
</dependency>
41-
4239
<dependency>
43-
<groupId>com.hazelcast</groupId>
44-
<artifactId>hazelcast-spring</artifactId>
45-
<version>${hazelcast.version}</version>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-data-redis</artifactId>
4642
</dependency>
47-
4843
<dependency>
49-
<groupId>com.hazelcast</groupId>
50-
<artifactId>hazelcast-hibernate53</artifactId>
51-
<version>${hazelcast-hibernate53.version}</version>
44+
<groupId>org.redisson</groupId>
45+
<artifactId>redisson-hibernate-53</artifactId>
46+
<version>${redisson-hibernate-53.version}</version>
5247
</dependency>
5348

49+
5450
<dependency>
5551
<groupId>com.h2database</groupId>
5652
<artifactId>h2</artifactId>

src/main/java/com/pj/redisdemo/config/HazelCastConfig.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/com/pj/redisdemo/domain/Employee.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
public class Employee
1414
{
1515
@Id
16-
private String empId;
17-
private String empName;
16+
private Long id;
17+
private String firstName;
18+
private String lastName;
19+
private String email;
20+
private String phone;
1821
}

src/main/java/com/pj/redisdemo/repository/EmployeeRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import com.pj.redisdemo.domain.Employee;
44
import org.springframework.data.jpa.repository.JpaRepository;
55

6-
public interface EmployeeRepository extends JpaRepository<Employee, String>
6+
public interface EmployeeRepository extends JpaRepository<Employee, Long>
77
{
88
}
Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
package com.pj.redisdemo.web;
22

3-
import com.hazelcast.client.HazelcastClient;
4-
import com.hazelcast.core.DistributedObject;
5-
import com.hazelcast.core.HazelcastInstance;
6-
import com.hazelcast.map.IMap;
73
import com.pj.redisdemo.domain.Employee;
84
import com.pj.redisdemo.repository.EmployeeRepository;
95
import org.springframework.web.bind.annotation.GetMapping;
106
import org.springframework.web.bind.annotation.PathVariable;
117
import org.springframework.web.bind.annotation.RequestMapping;
128
import org.springframework.web.bind.annotation.RestController;
139

14-
import java.util.Collection;
1510
import java.util.List;
1611
import java.util.Optional;
17-
import java.util.Random;
1812

1913
@RestController
2014
@RequestMapping("/api/v1/employee")
@@ -33,37 +27,9 @@ public List<Employee> findAll()
3327
return employeeRepository.findAll();
3428
}
3529

36-
@GetMapping("/find/{empId}")
37-
public Optional<Employee> findById(@PathVariable String empId)
30+
@GetMapping("/find/{id}")
31+
public Optional<Employee> findById(@PathVariable Long id)
3832
{
39-
return employeeRepository.findById(empId);
40-
}
41-
42-
@GetMapping("/create")
43-
public List<Employee> createNewEmployee()
44-
{
45-
Employee employee = new Employee();
46-
String empId = "emp" + new Random().nextInt();
47-
employee.setEmpId(empId);
48-
employee.setEmpName(empId);
49-
employeeRepository.saveAndFlush(employee);
50-
51-
return employeeRepository.findAll();
52-
}
53-
54-
@GetMapping("/clear")
55-
public void clear()
56-
{
57-
HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient();
58-
Collection<DistributedObject> distributedObjects = hazelcastInstance.getDistributedObjects();
59-
for (DistributedObject object : distributedObjects)
60-
{
61-
if (object instanceof IMap)
62-
{
63-
hazelcastInstance.getMap(object.getName()).destroy();
64-
System.out.println("Map destroyed=" + hazelcastInstance.getMap(object.getName()).getName());
65-
}
66-
}
67-
hazelcastInstance.shutdown();
33+
return employeeRepository.findById(id);
6834
}
6935
}

src/main/resources/application.properties

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/main/resources/application.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
3+
### Server information
4+
server:
5+
port: 8080
6+
7+
### Spring Properties
8+
spring:
9+
application:
10+
name: PRES 2.0
11+
cache:
12+
type: redis
13+
jackson:
14+
serialization:
15+
FAIL_ON_EMPTY_BEANS: false
16+
17+
### Spring datasource Properties
18+
datasource:
19+
url: jdbc:h2:mem:testdb
20+
username: sa
21+
password: password
22+
driver-class-name: org.h2.Driver
23+
initialization-mode: always
24+
25+
jpa:
26+
generate-ddl: true
27+
properties:
28+
hibernate:
29+
jdbc:
30+
time_zone: UTC
31+
ddl-auto: create-drop
32+
show_sql: true
33+
cache:
34+
use_query_cache: true
35+
use_second_level_cache: true
36+
factory_class: org.redisson.hibernate.RedissonRegionFactory
37+
redisson:
38+
fallback: true
39+
config: redission/redisson-dev.yaml
40+
41+
# Redis host details
42+
redis:
43+
host: localhost
44+
port: 6379

src/main/resources/data.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
INSERT INTO EMPLOYEE( ID , FIRST_NAME , LAST_NAME , EMAIL , PHONE) VALUES(1,'John','Doe','[email protected]','123-484-4994');
2+
INSERT INTO EMPLOYEE( ID , FIRST_NAME , LAST_NAME , EMAIL , PHONE) VALUES(2,'Jack','Ryan','[email protected]','123-484-4994');
3+
INSERT INTO EMPLOYEE( ID , FIRST_NAME , LAST_NAME , EMAIL , PHONE) VALUES(3,'Tome','Cruise','[email protected]','123-484-4994');

src/main/resources/docker/docker-hazelcast.yml renamed to src/main/resources/docker/docker-redis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ services:
33
redis:
44
image: redis
55
ports:
6-
- '5701:5701'
6+
- '6379:6379'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
singleServerConfig:
2+
address: "redis://localhost:6379"

0 commit comments

Comments
 (0)