Advertisement
FlyFar

lib/func/redis/read_all.dart

Jul 25th, 2023
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.62 KB | Cybersecurity | 0 0
  1. import 'package:redis/redis.dart';
  2.  
  3. import '../check.dart';
  4.  
  5. class redis {
  6.   List<dynamic> allKeys = [];
  7.   List<List<dynamic>> values = [];
  8.  
  9.   static Future<redis> readAll() async {
  10.     redis returnVal = redis();
  11.     final values = await getSignIn();
  12.     final conn = RedisConnection();
  13.     await conn
  14.         .connect(values["where"], values["port"])
  15.         .then((Command command) async {
  16.       await command.send_object(
  17.           ["AUTH", values["username"], values["pass"]]).then((_) async {
  18.         await command.send_object([
  19.           "KEYS",
  20.           "*",
  21.         ]).then((var response) async => {
  22.               returnVal.allKeys = response,
  23.               if (response is List)
  24.                 {
  25.                   for (var i in response)
  26.                     {
  27.                       await command
  28.                           .send_object(["LRANGE", i, 0, -1]).then((var all) {
  29.                         returnVal.values.add(all);
  30.                       })
  31.                     }
  32.                 }
  33.             });
  34.       });
  35.     });
  36.     return returnVal;
  37.   }
  38.  
  39.   static Future<List<dynamic>> readOneKey(String where) async {
  40.     List<dynamic> returnVal = [];
  41.     final values = await getSignIn();
  42.     final conn = RedisConnection();
  43.     await conn
  44.         .connect(values["where"], values["port"])
  45.         .then((Command command) async {
  46.       await command.send_object(
  47.           ["AUTH", values["username"], values["pass"]]).then((_) async {
  48.         await command.send_object(["LRANGE", where, 0, -1]).then((var all) {
  49.           returnVal = all;
  50.         });
  51.       });
  52.     });
  53.     return returnVal;
  54.   }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement