yr.kv_write#
- yr.kv_write(key: str, value: bytes, existence: ExistenceOpt = ExistenceOpt.NONE, write_mode: WriteMode = WriteMode.NONE_L2_CACHE, ttl_second: int = 0, cache_type: CacheType = CacheType.MEMORY) None[source]#
Provides the Redis class’s set storage interface, which supports saving binary data to the data system.
- Parameters:
key (str) – Sets a key for the data to be saved, which is used to identify the data. This key is used for querying the data and cannot be empty.
value (bytes) – The binary data to be stored. The maximum storage limit is 100M outside the cloud.
existence (ExistenceOpt, optional) – Whether to support overwriting of the Key. This parameter is optional and defaults to
ExistenceOpt.NONE, which means overwriting is allowed;ExistenceOpt.NXmeans overwriting is not allowed.write_mode (WriteMode, optional) – Sets the reliability of the data. When the server configuration supports secondary caching to ensure reliability (e.g., Redis service), this configuration can be used to ensure data reliability. This parameter is optional and defaults to
WriteMode.NONE_L2_CACHE.ttl_second (int, optional) – The data’s time-to-live (TTL) in seconds, after which the data will be deleted. This parameter is optional and defaults to
0, meaning the key will exist indefinitely until the kv_del interface is explicitly called.cache_type (CacheType, optional) – Sets the medium for data storage. This parameter is optional and defaults to
CacheType.MEMORY, which means storing in memory;CacheType.DISKmeans storing on disk.
- Returns:
None.
- Raises:
RuntimeError – If
kv_writeis called without initialization, an exception will be thrown.RuntimeError – If the data fails to be written to the data system.
Example
>>> import yr >>> yr.init() >>> >>> yr.kv_write("kv-key", b"value1", yr.ExistenceOpt.NONE, yr.WriteMode.NONE_L2_CACHE, 0, yr.CacheType.MEMORY) >>> >>> yr.finalize()