From 1d949900c97d96b173b3524da3117cc4e5c16961 Mon Sep 17 00:00:00 2001 From: NovaFox161 Date: Wed, 13 Mar 2024 01:01:49 -0500 Subject: [PATCH] Fix redis cache implementation bugs --- .../core/cache/RedisStringCacheRepository.kt | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/cache/RedisStringCacheRepository.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/cache/RedisStringCacheRepository.kt index 70506d69..d521efb3 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/cache/RedisStringCacheRepository.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/cache/RedisStringCacheRepository.kt @@ -51,27 +51,22 @@ class RedisStringCacheRepository( } override suspend fun getAll(guildId: Snowflake?): List { - try { - val keys = redisTemplate.scan(ScanOptions.scanOptions() - .type(DataType.STRING) - .match(formatKeySearch(guildId)) - .build() - ).collectList().awaitSingle() - if (keys.isEmpty()) return emptyList() - - val rawValues = valueOps.multiGetAndAwait(keys) - - return try { - rawValues.map { objectMapper.readValue(it, valueType) } - } catch (ex: Exception) { - LOGGER.error("Failed to read value from redis... evicting all | guildId:$guildId | keys:${keys.joinToString(",")} | data:${rawValues.joinToString(",")}", ex) - evictAll(guildId) + val keys = redisTemplate.scan(ScanOptions.scanOptions() + .type(DataType.STRING) + .match(formatKeySearch(guildId)) + .build() + ).collectList().awaitSingle() + if (keys.isEmpty()) return emptyList() - emptyList() - } + val rawValues = valueOps.multiGetAndAwait(keys) + + return try { + rawValues.map { objectMapper.readValue(it, valueType) } } catch (ex: Exception) { - LOGGER.error("Failed to fetch all | guildId:${guildId?.asLong()}", ex) - return emptyList() + LOGGER.error("Failed to read value from redis... evicting all | guildId:$guildId | keys:${keys.joinToString(",")} | data:${rawValues.joinToString(",")}", ex) + evictAll(guildId) + + emptyList() } } @@ -115,6 +110,7 @@ class RedisStringCacheRepository( .match(formatKeySearch(guildId)) .build() ).collectList().awaitSingle() + if (keys.isEmpty()) return redisTemplate.deleteAndAwait(*keys.toTypedArray()) }