encodeString method

bool encodeString(
  1. String key,
  2. String? value, [
  3. int? expireDurationInSecond
])

Encode an utf-8 string. expireDurationInSecond override the default duration setting from enableAutoKeyExpire().

Implementation

bool encodeString(String key, String? value, [int? expireDurationInSecond]) {
  if (value == null) {
    removeValue(key);
    return true;
  }

  final keyPtr = key.toNativeUtf8();
  final bytes = MMBuffer.fromList(const Utf8Encoder().convert(value))!;

  final ret = (expireDurationInSecond == null)
      ? _encodeBytes(_handle, keyPtr, bytes.pointer!, bytes.length)
      : _encodeBytesV2(_handle, keyPtr, bytes.pointer!, bytes.length, expireDurationInSecond);

  calloc.free(keyPtr);
  bytes.destroy();
  return _int2Bool(ret);
}