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

[FIX] 방문 횟수 조회 기능 성능 개선 #312

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class MemberService {
private final PlanFinder planFinder;
private final VisitSaver visitSaver;
private final VisitFinder visitFinder;
private final VisitCounter visitorCounter;

private final TrainingTimeService trainingTimeService;
private final GoalService goalService;
Expand Down
5 changes: 4 additions & 1 deletion smeem-external/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ dependencies {
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'
}

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.smeem.external.config;
package com.smeem.external.firebase.config;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.smeem.external.redis.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import lombok.val;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

@Value("${redis.host}")
private String redisHost;

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

@Bean
public ObjectMapper objectMapper() {
return JsonMapper.builder()
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true)
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true)
.findAndAddModules()
.build();
}

@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(redisHost, redisPort);
}

@Bean
public <T> RedisTemplate<String, T> redisTemplate() {
val redisTemplate = new RedisTemplate<String, T>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer(objectMapper()));
return redisTemplate;
}

@Bean
public GenericJackson2JsonRedisSerializer redisSerializer() {
return new GenericJackson2JsonRedisSerializer(objectMapper());
}

@Bean
public RedisCacheConfiguration redisCacheConfiguration() {
return RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
// .entryTtl(Duration.ofMinutes(1));
}

@Bean
public CacheManager cacheManager() {
return RedisCacheManager
.builder(redisConnectionFactory())
.cacheDefaults(redisCacheConfiguration())
.build();
}
}
8 changes: 8 additions & 0 deletions smeem-external/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
spring:
config:
activate:
on-profile: local

redis:
host: localhost
port: 6379
Loading