Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#61] 최근 방문한 매장 조회 기능 구현 #62

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

binaryyoung
Copy link
Contributor

  • 회원이 최근 방문한 매장을 조회하는 기능 추가

@binaryyoung binaryyoung self-assigned this Jan 3, 2020
@@ -18,7 +18,6 @@
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 레디스 설정파일이 2개일 때 오류가 나서 임시로 지웠는데 해결하면 다시 추가하겠습니다.

Copy link
Collaborator

@yyy9942 yyy9942 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bean의 등록과 DI가 어떻게 이루어지는지 살펴보면 더 좋을것같습니다.

@Bean
public LettuceConnectionFactory shopRedisConnectionFactory() { return new LettuceConnectionFactory(); }

@Bean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오류가 나는 이유는 동일 타입 Bean에 이름을 정해주지 않아서입니다. 해당 Bean에 이름을 정해준다면 오류를 해결할 수 있을것으로 보이네요. 다만 그렇다면 @Autowired 를 사용하는 RedisTemplate에 @Qualifire 어노테이션을 추가하여 어떤 Bean을 사용할지 정해주어야합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇군요. 참고해서 다시 적용해보겠습니다

public class ShopRedisConfig {

@Bean
public LettuceConnectionFactory shopRedisConnectionFactory() { return new LettuceConnectionFactory(); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LettuceConnectionFactory는 따로 옵션을 설정해 주자 않는건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

application.propertise에 spring.redis.port=6379 와 같이 설정을 해놓으면 자동으로 적용되어 따로 옵션을 설정해주진 않았습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bean이 제대로 주입되지 않아서 자동으로 적용되는것처럼 보이는 것 같습니다. 설정도 따로 분리하시는게 좋을 것 같네요. 명시적으로 config를 설정해주지않으면 자동으로 적용되지 않습니다

* @param shopId 매장 아이디
*/
public void add(String memberId, Long shopId) {
ZSetOperations<String, Long> zSetOperations = shopRedisTemplate.opsForZSet();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZSet을 사용한 이유가 있나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최근 조회한 매장 목록을 불러와야 되는데 list를 사용하면 데이터의 중복이 발생하고 중복을 막기위해 그냥 set을 사용하면 최근 조회한 매장 순서로 불러올 수 가 없었기 때문에 정렬된 셋인 ZSet을 사용하였습니다.

*/
public void add(String memberId, Long shopId) {
ZSetOperations<String, Long> zSetOperations = shopRedisTemplate.opsForZSet();
zSetOperations.add(RECENT_SHOP_VIEW_KEY + memberId, shopId, System.currentTimeMillis());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 키를 만드는 Factory가 있으면 좋을 것 같습니다. 여러 곳에서 같은 key를 참조해야할텐데 동일한 key 생성 로직을 하나의 메서드로 만들 수 있으니까요.

public class ShopRedisConfig {

@Bean
public LettuceConnectionFactory shopRedisConnectionFactory() { return new LettuceConnectionFactory(); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bean이 제대로 주입되지 않아서 자동으로 적용되는것처럼 보이는 것 같습니다. 설정도 따로 분리하시는게 좋을 것 같네요. 명시적으로 config를 설정해주지않으면 자동으로 적용되지 않습니다

redisTemplate.setConnectionFactory(shopRedisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Long.class));
return redisTemplate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 옵션들을 설정한 의도를 주석으로 설명해주시면 좋을 것 같습니다~

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants