set method

Future<bool> set(
  1. String key,
  2. String message, {
  3. Duration? lifetime,
})

Sets a String in the Redis cache, which optionally expires.

Implementation

Future<bool> set(String key, String message, {Duration? lifetime}) async {
  await _connect();
  try {
    var object = ['SET', key, message];
    if (lifetime != null) {
      object.addAll(['PX', '${lifetime.inMilliseconds}']);
    }
    var result = await _command?.send_object(object);
    return result == 'OK';
  } catch (e) {
    _invalidateCommand();
    return false;
  }
}