티스토리 뷰
1. Go to your aws console and search 'ElastiCache'.
2. Create 'Redis Cluster'.
3. Select options for a project and create a cluster.
4. Go to 'Security Groups' in the side menu of 'EC2' and create security group.
5. Fill in the form.
5-1. Add two inbound rules for IPv4 and IPv6. 6379 is the default port number.
5-2. Adding outbound rules is optional.
5-3. Create a security group.
6. Create and run a redis docker.
docker run --name board-redis -p 6379:6379 -d redis:latest
7. Add a dependency and configure a project.
## for build.gradle.kts
implementation("org.springframework.boot:spring-boot-starter-data-redis")
## for application-local.yml
cache:
type: redis
redis:
host: localhost
port: 6379
## for application-dev.yml
cache:
type: redis
redis:
host: ## aws endpoint
port: 6379
8. Configure within a project.
@Configuration
class RedisConfig {
@Value("\${spring.cache.redis.host}")
lateinit var host: String
@Value("\${spring.cache.redis.port}")
lateinit var port: String
@Bean
fun redisConnectionFactory(): RedisConnectionFactory {
return LettuceConnectionFactory(host, port.toInt())
}
@Bean
fun redisTemplate(): RedisTemplate<String, Any> {
val redisTemplate = RedisTemplate<String, Any>()
redisTemplate.connectionFactory = redisConnectionFactory()
redisTemplate.keySerializer = StringRedisSerializer()
redisTemplate.valueSerializer = StringRedisSerializer()
return redisTemplate
}
}
@Service
class RedisUtil(
private val redisTemplate: RedisTemplate<String, Any>,
) {
fun setData(key: String, value: Any) {
redisTemplate.opsForValue().set(key, value.toString())
}
fun getData(key: String): Any? {
return redisTemplate.opsForValue().get(key)
}
}
9. Add a dependency of testcontainer
testImplementation("io.kotest.extensions:kotest-extensions-testcontainers:2.0.2")
10. Inject redisUtil to service where it is needed.
11. Include redisContainer in test codes to avoid errors.
## docker image tag should be identical to No.6
val redisContainer = GenericContainer<Nothing>("redis:latest")
beforeSpec {
redisContainer.portBindings.add("16379:6379")
redisContainer.start()
listener(redisContainer.perSpec())
}
afterSpec {
redisContainer.stop()
}
12. Check the logs after triggering api. Make sure that caching with redis works from the second query.
13. Check if the shard and nodes were generated within the redis cluster.
14. Modify the default security group with the made one.
15. Copy the configuration endpoint of the redis cluster and paste it into the "host" field in application-dev.yml.
16. Deploy the project on AWS.
- Total
- Today
- Yesterday
- mvvm
- flutter_android_app_links
- Android
- futter_api
- FlutterWirelessDebuginAOS
- retrofit_toJson()_error
- querydslKotlinError
- retrofit_generator_conflicts_with_freezed
- android_app_links
- FirebaseConfigurationForMultipleBuildTypes
- MultipleFirebaseEnvironments
- unsplashAPI
- flutter_storage_not_working_for_the_first_time
- phplaravel
- querydsl5.0.0jakarta
- android_domain
- android_app_link_domain_works_with_adb_but_not_works_with_browser
- laravel9
- android_app_links_domain
- Laravel
- dagger-hilt
- flutter_secure_storage_issue_iOS
- flutter
- Kotlin
- RunAFlutterProjectIniPhoneFromVSCode
- KotlinFlow
- retrofit_generator
- AndroidWirelessDebug
- WirelessDebug
- querydslQclass
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |