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()) }