Skip to content

Commit 716e3eb

Browse files
authored
Reconnect when a redis command fails (#236)
1 parent 9255e5e commit 716e3eb

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Diff for: neat_cache/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v2.0.4
2+
* Reconnect when a redis command fails.
3+
14
## v2.0.3
25
* Added `topics` to `pubspec.yaml`.
36

Diff for: neat_cache/lib/src/providers/redis.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ class RedisCacheProvider extends CacheProvider<List<int>> {
131131
try {
132132
return await fn(ctx.client).timeout(_commandTimeLimit);
133133
} on RedisCommandException catch (e) {
134-
throw AssertionError('error from redis command: $e');
134+
// We don't really know what happened, let's log shout it.
135+
// It could be a sign that something really bad is happening to redis.
136+
// Best shutdown the connection and try again.
137+
_log.shout('Error from redis command: $e');
138+
await ctx.client.close(force: true);
139+
throw IntermittentCacheException('error from redis command: $e');
135140
} on TimeoutException {
136141
// If we had a timeout, doing the command we forcibly disconnect
137142
// from the server, such that next retry will use a new connection.

Diff for: neat_cache/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: neat_cache
2-
version: 2.0.3
2+
version: 2.0.4
33
description: >-
44
A neat cache abstraction for wrapping in-memory or redis caches.
55
homepage: https://github.com/google/dart-neats/tree/master/neat_cache

0 commit comments

Comments
 (0)