新增redis二进制数据存储

This commit is contained in:
2025-07-22 17:28:52 +08:00
parent b20546414c
commit 1e57d49ac4

View File

@@ -1,3 +1,5 @@
import 'dart:typed_data';
import 'package:redis/redis.dart'; import 'package:redis/redis.dart';
class Redis { class Redis {
@@ -70,6 +72,23 @@ class Redis {
} }
} }
Future<bool> 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<String?> get(String key) async { Future<String?> get(String key) async {
try { try {
return await _command?.send_object(["GET", key]); return await _command?.send_object(["GET", key]);
@@ -79,6 +98,15 @@ class Redis {
} }
} }
Future<dynamic> getData(String key) async {
try {
return await _command?.send_object(["GET", key]);
} catch (e) {
print(e);
return null;
}
}
Future<bool> delete(String key) async { Future<bool> delete(String key) async {
try { try {
return await _command?.send_object(["DEL", key]) == "OK"; return await _command?.send_object(["DEL", key]) == "OK";