run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() => withApp((app) async {
  final config = App.make<ConfigRepository>();
  final redis = config.section<RedisConfig>();
  final cachePrefix =
      '${redis.prefix}${config.section<CacheConfig>().prefix}';
  final match = argResults!['match'] as String? ?? '${redis.prefix}*';
  final audit = await auditRedisKeys(
    Redis.connection(_connection(this)),
    match: match,
    cachePrefix: cachePrefix,
    limit: int.tryParse(argResults!['limit']! as String) ?? 20,
  );
  stdout.writeln('${audit.keys} keys match $match');
  for (final MapEntry(key: type, value: count) in audit.types.entries) {
    stdout.writeln('  $type: $count');
  }
  stdout.writeln('${audit.withoutTtl} without a time to live');
  if (audit.cacheWithoutTtl.isNotEmpty) {
    stdout.writeln('Cache keys that never expire (forever(), or a leak):');
    for (final key in audit.cacheWithoutTtl) {
      stdout.writeln('  $key');
    }
  }
  return 0;
});