여러대의 Redis와 Valkey에 연결할 수 있도록 환경설정
This commit is contained in:
parent
831bd731ca
commit
157e3a39b6
|
@ -2,17 +2,12 @@ package kr.co.vividnext.sodalive.admin.calculate
|
|||
|
||||
import kr.co.vividnext.sodalive.creator.admin.calculate.GetCreatorCalculateCommunityPostResponse
|
||||
import kr.co.vividnext.sodalive.extensions.convertLocalDateTime
|
||||
import org.springframework.cache.annotation.Cacheable
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
@Service
|
||||
class AdminCalculateService(private val repository: AdminCalculateQueryRepository) {
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'calculateLive:' + " + "#startDateStr + ':' + #endDateStr"
|
||||
)
|
||||
fun getCalculateLive(startDateStr: String, endDateStr: String): List<GetCalculateLiveResponse> {
|
||||
val startDate = startDateStr.convertLocalDateTime()
|
||||
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
@ -23,10 +18,6 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'calculateContent:' + " + "#startDateStr + ':' + #endDateStr"
|
||||
)
|
||||
fun getCalculateContentList(startDateStr: String, endDateStr: String): List<GetCalculateContentResponse> {
|
||||
val startDate = startDateStr.convertLocalDateTime()
|
||||
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
@ -37,10 +28,6 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'cumulativeSalesByContent:' + " + "#offset + ':' + #limit"
|
||||
)
|
||||
fun getCumulativeSalesByContent(offset: Long, limit: Long): GetCumulativeSalesByContentResponse {
|
||||
val totalCount = repository.getCumulativeSalesByContentTotalCount()
|
||||
val items = repository
|
||||
|
@ -51,10 +38,6 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'calculateContentDonationList2:' + " + "#startDateStr + ':' + #endDateStr"
|
||||
)
|
||||
fun getCalculateContentDonationList(
|
||||
startDateStr: String,
|
||||
endDateStr: String
|
||||
|
@ -68,10 +51,6 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'calculateCommunityPost:' + " + "#startDateStr + ':' + #endDateStr + ':' + #offset"
|
||||
)
|
||||
fun getCalculateCommunityPost(
|
||||
startDateStr: String,
|
||||
endDateStr: String,
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package kr.co.vividnext.sodalive.configs
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.FilterType
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(
|
||||
basePackages = ["kr.co.vividnext.sodalive"],
|
||||
includeFilters = [
|
||||
ComponentScan.Filter(
|
||||
type = FilterType.ASSIGNABLE_TYPE,
|
||||
classes = [org.springframework.data.jpa.repository.JpaRepository::class]
|
||||
)
|
||||
]
|
||||
)
|
||||
class JpaConfig
|
|
@ -1,32 +1,40 @@
|
|||
package kr.co.vividnext.sodalive.configs
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.cache.annotation.EnableCaching
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration
|
||||
import org.springframework.data.redis.cache.RedisCacheManager
|
||||
import org.springframework.context.annotation.FilterType
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
|
||||
import org.springframework.data.redis.core.RedisTemplate
|
||||
import org.springframework.data.redis.core.StringRedisTemplate
|
||||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer
|
||||
import java.time.Duration
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@EnableRedisRepositories
|
||||
@EnableRedisRepositories(
|
||||
basePackages = ["kr.co.vividnext.sodalive"],
|
||||
redisTemplateRef = "redisTemplate",
|
||||
excludeFilters = [
|
||||
ComponentScan.Filter(
|
||||
type = FilterType.REGEX,
|
||||
pattern = ["kr\\.co\\.vividnext\\.sodalive\\.v2\\..*"]
|
||||
),
|
||||
ComponentScan.Filter(
|
||||
type = FilterType.ASSIGNABLE_TYPE,
|
||||
classes = [org.springframework.data.jpa.repository.JpaRepository::class]
|
||||
)
|
||||
]
|
||||
)
|
||||
class RedisConfig(
|
||||
@Value("\${spring.redis.host}")
|
||||
private val host: String,
|
||||
@Value("\${spring.redis.port}")
|
||||
private val port: Int
|
||||
) {
|
||||
@Bean
|
||||
@Bean(name = ["redisConnectionFactory"])
|
||||
fun redisConnectionFactory(): RedisConnectionFactory {
|
||||
val clientConfiguration = LettuceClientConfiguration.builder()
|
||||
.useSsl()
|
||||
|
@ -36,53 +44,15 @@ class RedisConfig(
|
|||
return LettuceConnectionFactory(RedisStandaloneConfiguration(host, port), clientConfiguration)
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Bean(name = ["redisTemplate"])
|
||||
fun redisTemplate(): RedisTemplate<*, *> {
|
||||
val redisTemplate: RedisTemplate<*, *> = RedisTemplate<Any, Any>()
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory())
|
||||
return redisTemplate
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun cacheManager(redisConnectionFactory: RedisConnectionFactory): RedisCacheManager {
|
||||
val defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofMinutes(30))
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer()))
|
||||
.serializeValuesWith(
|
||||
RedisSerializationContext.SerializationPair.fromSerializer(
|
||||
GenericJackson2JsonRedisSerializer()
|
||||
)
|
||||
)
|
||||
|
||||
val cacheConfigMap = mutableMapOf<String, RedisCacheConfiguration>()
|
||||
cacheConfigMap["default"] = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofMinutes(30))
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer()))
|
||||
.serializeValuesWith(
|
||||
RedisSerializationContext.SerializationPair.fromSerializer(
|
||||
GenericJackson2JsonRedisSerializer()
|
||||
)
|
||||
)
|
||||
cacheConfigMap["cache_ttl_3_days"] = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofDays(3))
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer()))
|
||||
.serializeValuesWith(
|
||||
RedisSerializationContext.SerializationPair.fromSerializer(
|
||||
GenericJackson2JsonRedisSerializer()
|
||||
)
|
||||
)
|
||||
cacheConfigMap["cache_ttl_3_hours"] = RedisCacheConfiguration.defaultCacheConfig()
|
||||
.entryTtl(Duration.ofHours(3))
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer()))
|
||||
.serializeValuesWith(
|
||||
RedisSerializationContext.SerializationPair.fromSerializer(
|
||||
GenericJackson2JsonRedisSerializer()
|
||||
)
|
||||
)
|
||||
|
||||
return RedisCacheManager.builder(redisConnectionFactory)
|
||||
.cacheDefaults(defaultCacheConfig)
|
||||
.withInitialCacheConfigurations(cacheConfigMap)
|
||||
.build()
|
||||
@Bean(name = ["redisStringRedisTemplate"])
|
||||
fun redisStringRedisTemplate(): StringRedisTemplate {
|
||||
return StringRedisTemplate(redisConnectionFactory())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package kr.co.vividnext.sodalive.configs
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.FilterType
|
||||
import org.springframework.data.redis.connection.RedisClusterConfiguration
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
|
||||
import org.springframework.data.redis.core.RedisTemplate
|
||||
import org.springframework.data.redis.core.StringRedisTemplate
|
||||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories
|
||||
import java.time.Duration
|
||||
|
||||
@Configuration
|
||||
@EnableRedisRepositories(
|
||||
basePackages = ["kr.co.vividnext.sodalive.v2"],
|
||||
redisTemplateRef = "valkeyTemplate",
|
||||
includeFilters = [
|
||||
ComponentScan.Filter(
|
||||
type = FilterType.REGEX,
|
||||
pattern = ["kr\\.co\\.vividnext\\.sodalive\\.v2\\..*"]
|
||||
)
|
||||
],
|
||||
excludeFilters = [
|
||||
ComponentScan.Filter(
|
||||
type = FilterType.ASSIGNABLE_TYPE,
|
||||
classes = [org.springframework.data.jpa.repository.JpaRepository::class]
|
||||
)
|
||||
]
|
||||
)
|
||||
class ValkeyConfig(
|
||||
@Value("\${spring.valkey.host}")
|
||||
private val host: String,
|
||||
@Value("\${spring.valkey.port}")
|
||||
private val port: Int
|
||||
) {
|
||||
@Bean(name = ["valkeyConnectionFactory"])
|
||||
fun valkeyConnectionFactory(): RedisConnectionFactory {
|
||||
val clusterConfig = RedisClusterConfiguration()
|
||||
clusterConfig.clusterNode(host, port)
|
||||
|
||||
val clientConfig = LettuceClientConfiguration.builder()
|
||||
.commandTimeout(Duration.ofSeconds(5))
|
||||
.shutdownTimeout(Duration.ofSeconds(5))
|
||||
.useSsl()
|
||||
.disablePeerVerification()
|
||||
.build()
|
||||
|
||||
return LettuceConnectionFactory(clusterConfig, clientConfig)
|
||||
}
|
||||
|
||||
@Bean(name = ["valkeyTemplate"])
|
||||
fun valkeyTemplate(): RedisTemplate<*, *> {
|
||||
val redisTemplate: RedisTemplate<*, *> = RedisTemplate<Any, Any>()
|
||||
redisTemplate.setConnectionFactory(valkeyConnectionFactory())
|
||||
return redisTemplate
|
||||
}
|
||||
|
||||
@Bean(name = ["valkeyStringRedisTemplate"])
|
||||
fun valkeyStringRedisTemplate(): StringRedisTemplate {
|
||||
return StringRedisTemplate(valkeyConnectionFactory())
|
||||
}
|
||||
}
|
|
@ -28,7 +28,6 @@ import kr.co.vividnext.sodalive.member.Member
|
|||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import kr.co.vividnext.sodalive.utils.generateFileName
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.cache.annotation.Cacheable
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
|
@ -717,11 +716,6 @@ class AudioContentService(
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_days"],
|
||||
key = "'contentRanking:' + ':' +" +
|
||||
"#isAdult + ':' + #startDate + ':' + #endDate + ':' + #sortType + ':' + #offset + ':' + #limit"
|
||||
)
|
||||
fun getAudioContentRanking(
|
||||
isAdult: Boolean,
|
||||
startDate: LocalDateTime,
|
||||
|
|
|
@ -10,7 +10,6 @@ import kr.co.vividnext.sodalive.event.EventItem
|
|||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.cache.annotation.Cacheable
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
@ -27,7 +26,6 @@ class AudioContentMainService(
|
|||
private val imageHost: String
|
||||
) {
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(cacheNames = ["default"], key = "'themeList:' + ':' + #isAdult")
|
||||
fun getThemeList(isAdult: Boolean): List<String> {
|
||||
return audioContentThemeRepository.getActiveThemeOfContent(isAdult = isAdult)
|
||||
}
|
||||
|
@ -81,7 +79,6 @@ class AudioContentMainService(
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(cacheNames = ["default"], key = "'newContentUploadCreatorList:' + #memberId + ':' + #isAdult")
|
||||
fun getNewContentUploadCreatorList(memberId: Long, isAdult: Boolean): List<GetNewContentUploadCreator> {
|
||||
return repository.getNewContentUploadCreatorList(
|
||||
cloudfrontHost = imageHost,
|
||||
|
@ -93,7 +90,6 @@ class AudioContentMainService(
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(cacheNames = ["default"], key = "'contentMainBannerList:' + #memberId + ':' + #isAdult")
|
||||
fun getAudioContentMainBannerList(memberId: Long, isAdult: Boolean) =
|
||||
repository.getAudioContentMainBannerList(isAdult = isAdult)
|
||||
.asSequence()
|
||||
|
@ -156,11 +152,6 @@ class AudioContentMainService(
|
|||
.toList()
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["default"],
|
||||
key = "'getAudioContentCurationListWithPaging:' + #memberId + ':' + #isAdult + ':' + #contentType" +
|
||||
"+ ':' + #offset + ':' + #limit"
|
||||
)
|
||||
fun getAudioContentCurationListWithPaging(
|
||||
memberId: Long,
|
||||
isAdult: Boolean,
|
||||
|
|
|
@ -4,17 +4,12 @@ import kr.co.vividnext.sodalive.admin.calculate.GetCalculateLiveResponse
|
|||
import kr.co.vividnext.sodalive.admin.calculate.GetCumulativeSalesByContentResponse
|
||||
import kr.co.vividnext.sodalive.extensions.convertLocalDateTime
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import org.springframework.cache.annotation.Cacheable
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
@Service
|
||||
class CreatorAdminCalculateService(private val repository: CreatorAdminCalculateQueryRepository) {
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["default"],
|
||||
key = "'creatorCalculateLive:v20240403_01:' + " + "#member + ':' + #startDateStr + ':' + #endDateStr"
|
||||
)
|
||||
fun getCalculateLive(startDateStr: String, endDateStr: String, member: Member): List<GetCalculateLiveResponse> {
|
||||
val startDate = startDateStr.convertLocalDateTime()
|
||||
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
@ -25,11 +20,6 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'creatorCalculateContentList:v20240403_01:' + " +
|
||||
"#startDateStr + ':' + #endDateStr + ':' + #memberId + ':' + #offset + ':' + #limit"
|
||||
)
|
||||
fun getCalculateContentList(
|
||||
startDateStr: String,
|
||||
endDateStr: String,
|
||||
|
@ -48,10 +38,6 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'creatorCumulativeSalesByContent:' + " + "#memberId + ':' + #offset + ':' + #limit"
|
||||
)
|
||||
fun getCumulativeSalesByContent(memberId: Long, offset: Long, limit: Long): GetCumulativeSalesByContentResponse {
|
||||
val totalCount = repository.getCumulativeSalesByContentTotalCount(memberId)
|
||||
val items = repository
|
||||
|
@ -62,11 +48,6 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'creatorCalculateContentDonationList2:' + " +
|
||||
"#startDateStr + ':' + #endDateStr + ':' + #memberId + ':' + #offset + ':' + #limit"
|
||||
)
|
||||
fun getCalculateContentDonationList(
|
||||
startDateStr: String,
|
||||
endDateStr: String,
|
||||
|
@ -86,11 +67,6 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate
|
|||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'creatorCalculateCommunityPost:' + " +
|
||||
"#startDateStr + ':' + #endDateStr + ':' + #memberId + ':' + #offset + ':' + #limit"
|
||||
)
|
||||
fun getCalculateCommunityPost(
|
||||
startDateStr: String,
|
||||
endDateStr: String,
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package kr.co.vividnext.sodalive.live.roulette
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.data.redis.core.StringRedisTemplate
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class RedisIdGenerator(private val stringRedisTemplate: StringRedisTemplate) {
|
||||
class RedisIdGenerator(
|
||||
@Qualifier("redisStringRedisTemplate") private val stringRedisTemplate: StringRedisTemplate
|
||||
) {
|
||||
fun generateId(key: String): Long {
|
||||
return stringRedisTemplate.opsForValue().increment(key, 1) ?: 1L
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package kr.co.vividnext.sodalive.v2
|
||||
|
||||
import kr.co.vividnext.sodalive.member.token.MemberToken
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface NewMemberTokenRepository : CrudRepository<MemberToken, Long>
|
|
@ -52,6 +52,10 @@ jwt:
|
|||
secret: ${JWT_SECRET}
|
||||
|
||||
spring:
|
||||
valkey:
|
||||
host: ${VALKEY_HOST}
|
||||
port: ${VALKEY_PORT}
|
||||
|
||||
redis:
|
||||
host: ${REDIS_HOST}
|
||||
port: ${REDIS_PORT}
|
||||
|
|
Loading…
Reference in New Issue