set method
Sets a value for the given key. Returns true
, if the value was successfully set. Otherwise, false
is returned.
Implementation
Future<bool> set(String key, Object value, {Duration? expire, SetMode? mode}) async {
final cmd = ['SET', key, value];
if (expire != null) {
cmd.addAll(['PX', '${expire.inMilliseconds}']);
}
if (mode == SetMode.onlyIfNotExists) {
cmd.add('NX');
} else if (mode == SetMode.onlyIfExists) {
cmd.add('XX');
}
final result = await _execCmd(cmd);
return _getSimpleString(result) == 'OK';
}