package com.wzj.soopin.member.util;

import com.wzj.soopin.member.domain.po.Member;
import com.wzj.soopin.member.mapper.MemberMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.redis.redis.RedisCache;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Slf4j
@RequiredArgsConstructor
public class MemberCacheHelper {

    public static final String MEMBER_INFO_CACHE = "member:info:";

    public static final String MEMBER_ACCOUNT_CACHE = "member:account:";

    private final RedisCache redisCache;

    private final MemberMapper memberMapper;


    public Member getMemberInfo(Long memberId) {
        Member member= redisCache.getCacheObject(MEMBER_INFO_CACHE + memberId);
        if(member==null){
            member=memberMapper.selectById(memberId);
            redisCache.setCacheObject(MEMBER_INFO_CACHE + memberId,member);
        }
        return member;
    }
}
