From fd94d2d14242de8b2a541a5b7bbd66caded926c0 Mon Sep 17 00:00:00 2001 From: Bryan Oltman Date: Tue, 2 Dec 2025 13:48:15 -0500 Subject: [PATCH] fix(redis_client): remove other casts of results to List (#3414) --- .../redis_client/lib/src/redis_client.dart | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/packages/redis_client/lib/src/redis_client.dart b/packages/redis_client/lib/src/redis_client.dart index 5e5c58d2..5c84a018 100644 --- a/packages/redis_client/lib/src/redis_client.dart +++ b/packages/redis_client/lib/src/redis_client.dart @@ -174,7 +174,10 @@ class RedisClient { /// Equivalent to the `KEYS` command. /// https://redis.io/commands/keys Future> keys({required String pattern}) async { - final rawResult = await execute(['KEYS', pattern]) as List; + final rawResult = await execute(['KEYS', pattern]); + if (rawResult is! List) { + throw RedisException(rawResult.toString()); + } return rawResult .whereType() .map( @@ -227,7 +230,10 @@ class RedisClient { /// Equivalent to the `MGET` command. /// https://redis.io/commands/mget Future> mget({required List keys}) async { - final results = await execute(['MGET', ...keys]) as List; + final results = await execute(['MGET', ...keys]); + if (results is! List) { + throw RedisException(results.toString()); + } return results.map((result) => result.payload).toList(); } @@ -841,7 +847,11 @@ class RedisTimeSeries { Future<({DateTime timestamp, double value})?> get({ required String key, }) async { - final result = await _client.execute(['TS.GET', key]) as List; + final result = await _client.execute(['TS.GET', key]); + if (result is! List) { + throw RedisException(result.toString()); + } + if (result.isEmpty) return null; final timestamp = result[0] as RespInteger; final value = result[1] as RespSimpleString; @@ -895,7 +905,10 @@ class RedisTimeSeries { } return results.map((result) { - final payload = result.payload as List; + final payload = result.payload; + if (payload == null || payload is! List) { + throw RedisException(payload.toString()); + } final timestamp = payload[0] as RespInteger; final value = payload[1] as RespSimpleString; return ( @@ -956,13 +969,15 @@ class RedisTDigest { required String key, required List quantiles, }) async { - final results = - await _client.execute([ - 'TDIGEST.QUANTILE', - key, - ...quantiles.map((quantile) => quantile.toString()), - ]) - as List; + final results = await _client.execute([ + 'TDIGEST.QUANTILE', + key, + ...quantiles.map((quantile) => quantile.toString()), + ]); + + if (results is! List) { + throw RedisException(results.toString()); + } return results.map((result) { if (result is RespBulkString && result.payload != null) {