Skip to content

Commit

Permalink
Reconnect when a redis command fails (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj authored Apr 11, 2024
1 parent 9255e5e commit 716e3eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions neat_cache/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v2.0.4
* Reconnect when a redis command fails.

## v2.0.3
* Added `topics` to `pubspec.yaml`.

Expand Down
7 changes: 6 additions & 1 deletion neat_cache/lib/src/providers/redis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ class RedisCacheProvider extends CacheProvider<List<int>> {
try {
return await fn(ctx.client).timeout(_commandTimeLimit);
} on RedisCommandException catch (e) {
throw AssertionError('error from redis command: $e');
// We don't really know what happened, let's log shout it.
// It could be a sign that something really bad is happening to redis.
// Best shutdown the connection and try again.
_log.shout('Error from redis command: $e');
await ctx.client.close(force: true);
throw IntermittentCacheException('error from redis command: $e');
} on TimeoutException {
// If we had a timeout, doing the command we forcibly disconnect
// from the server, such that next retry will use a new connection.
Expand Down
2 changes: 1 addition & 1 deletion neat_cache/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: neat_cache
version: 2.0.3
version: 2.0.4
description: >-
A neat cache abstraction for wrapping in-memory or redis caches.
homepage: https://github.com/google/dart-neats/tree/master/neat_cache
Expand Down

0 comments on commit 716e3eb

Please sign in to comment.