yr.kv_set#
- yr.kv_set(key: str, value: bytes, set_param: ~yr.base_runtime.SetParam = SetParam(existence=<ExistenceOpt.NONE: 0>, write_mode=<WriteMode.NONE_L2_CACHE: 0>, ttl_second=0, cache_type=<CacheType.MEMORY: 0>)) None[source]#
Provide a set storage interface similar to Redis, supporting the saving of binary data to the data system.
- Parameters:
key (str) – Set a key for the saved data to identify it. Use this key to query data. It cannot be empty.
value (bytes) – Binary data to be stored. The maximum storage limit outside the cloud is
100M.set_param (SetParam) – The configuration parameters of kv write in the data system include
existence,write_mode,ttl_secondandcache_type.
- Returns:
None.
- Raises:
RuntimeError – If
kv_setis not initialized and called, an exception will be thrown.RuntimeError – If the data writing to the data system fails.
Example
>>> import yr >>> yr.init() >>> # The worker startup parameters need to be configured with shared_disk_directory and shared_disk_size_mb; >>> # otherwise, this example will result in an error >>> set_param = yr.SetParam() >>> set_param.existence = yr.ExistenceOpt.NX >>> set_param.write_mode = yr.WriteMode.NONE_L2_CACHE_EVICT >>> set_param.ttl_second = 10 >>> yr.kv_set("kv-key", b"value1", set_param) >>> >>> yr.finalize()