spring-web-modules/api/src/main/kotlin/com/cubetiqs/web/modules/redis/RedisController.kt
Sambo Chea 8c999a9e7c
Some checks failed
continuous-integration/drone/push Build is failing
Add basic module and redis data with jpa and example
2022-04-11 12:35:47 +07:00

31 lines
951 B
Kotlin

package com.cubetiqs.web.modules.redis
import com.cubetiqs.web.util.RouteConstants
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.web.bind.annotation.*
@RedisModule
@Tag(name = "Redis Controller")
@RestController
@RequestMapping(RouteConstants.INDEX + "redis")
class RedisController @Autowired constructor(
private val redisTemplate: RedisTemplate<String, RedisKVModel>,
) {
@GetMapping("/{key}")
fun getAll(
@PathVariable("key") key: String,
): Collection<RedisKVModel?> {
return redisTemplate.opsForValue().multiGet(listOf(key)) ?: listOf()
}
@PostMapping("/{key}")
fun set(
@PathVariable("key") key: String,
@RequestBody body: RedisKVModel
): RedisKVModel {
redisTemplate.opsForValue().set(key, body)
return body
}
}