Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feature: #4 redis test #36

Merged
merged 17 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/cotato/growingpain/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cotato.growingpain.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;

@Configuration
@EnableRedisRepositories
public class RedisConfig {
@Value("${spring.data.redis.host}")
private String host;

@Value("${spring.data.redis.port}")
private int port;

@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(host, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
public enum ApplicationType {

DOCUMENT("서류"),
INTERVIEW("면접");
INTERVIEW("면접"),
INTERVIEW_FEEDBACK("면접 피드백"),
BUSINESS_ANALYSIS("기업 분석");

private final String description;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ActivityLog extends BaseTimeEntity {
private String role;

@Column(name = "contribution")
private String contribution;
private int contribution;

@Column(name = "activity_start_date")
private String activityStartDate;
Expand Down Expand Up @@ -83,7 +83,7 @@ public ActivityLog(
String content,
String performance,
String role,
String contribution,
Integer contribution,
String activityStartDate,
String activityCloseDate,
String imageUrl,
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/cotato/growingpain/test/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cotato.growingpain.test;

import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import java.time.LocalDateTime;
import lombok.Getter;
import org.springframework.data.redis.core.RedisHash;

@Getter
@RedisHash(value = "people", timeToLive = 30)
public class Person {

@Id
@GeneratedValue
private String id;
private String name;
private Integer age;
private LocalDateTime createdAt;

public Person(String name, Integer age) {
this.name = name;
this.age = age;
this.createdAt = LocalDateTime.now();
}
}
8 changes: 8 additions & 0 deletions src/main/java/cotato/growingpain/test/PersonRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cotato.growingpain.test;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PersonRepository extends CrudRepository<Person, String> {
}
8 changes: 7 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ spring:
show-sql: true
properties:
hibernate:
format_sql: true
format_sql: true
dialect: org.hibernate.dialect.MySQLDialect

data:
redis:
host: localhost
port: 6379
31 changes: 31 additions & 0 deletions src/test/java/cotato/growingpain/RedisRepositoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cotato.growingpain;

import cotato.growingpain.test.Person;
import cotato.growingpain.test.PersonRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class RedisRepositoryTest {

@Autowired
private PersonRepository repo;

@Test
void test() {
Person person = new Person("narong", 25);

// 저장
repo.save(person);

// `keyspace:id` 값을 가져옴
repo.findById(person.getId());

// Person Entity 의 @RedisHash 에 정의되어 있는 keyspace (people) 에 속한 키의 갯수를 구함
repo.count();

// 삭제
repo.delete(person);
}
}