新增redis二进制数据存储
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:redis/redis.dart';
|
||||
|
||||
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 {
|
||||
try {
|
||||
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 {
|
||||
try {
|
||||
return await _command?.send_object(["DEL", key]) == "OK";
|
||||
|
||||
Reference in New Issue
Block a user