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";