From 1e57d49ac4a4401a457742e20bd0b5f38380371a Mon Sep 17 00:00:00 2001 From: qmqz Date: Tue, 22 Jul 2025 17:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eredis=E4=BA=8C=E8=BF=9B?= =?UTF-8?q?=E5=88=B6=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/redis/redis.dart | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/base/redis/redis.dart b/lib/base/redis/redis.dart index 86831d8..f46f8d3 100644 --- a/lib/base/redis/redis.dart +++ b/lib/base/redis/redis.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + import 'package:redis/redis.dart'; class Redis { @@ -70,6 +72,23 @@ class Redis { } } + Future setData(String key, dynamic value, {int? ttl}) async { + try { + var response; + var val = value is String ? value : RedisBulk(value); + if (ttl != null) { + response = + await _command?.send_object(["SETEX", key, ttl.toString(), val]); + } else { + response = await _command?.send_object(["SET", key, val]); + } + return response == "OK"; + } catch (e) { + print(e); + return false; + } + } + Future get(String key) async { try { return await _command?.send_object(["GET", key]); @@ -79,6 +98,15 @@ class Redis { } } + Future getData(String key) async { + try { + return await _command?.send_object(["GET", key]); + } catch (e) { + print(e); + return null; + } + } + Future delete(String key) async { try { return await _command?.send_object(["DEL", key]) == "OK";