Skip to content

Commit

Permalink
Fix redis cache implementation bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Mar 13, 2024
1 parent 9f225ba commit 1d94990
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,22 @@ class RedisStringCacheRepository<K, V>(
}

override suspend fun getAll(guildId: Snowflake?): List<V> {
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()
}
}

Expand Down Expand Up @@ -115,6 +110,7 @@ class RedisStringCacheRepository<K, V>(
.match(formatKeySearch(guildId))
.build()
).collectList().awaitSingle()
if (keys.isEmpty()) return

redisTemplate.deleteAndAwait(*keys.toTypedArray())
}
Expand Down

0 comments on commit 1d94990

Please sign in to comment.