Use kv.set() to store string values and kv.get() to retrieve them. kv.get() returns null if the key does not exist or has expired. kv.set() supports several powerful options:
NX: Only set the key if it does not already exist.XX: Only set the key if it already exists.GET: Returns the existing value while setting the new one.EX: Set an expiration time in seconds.PX: Set an expiration time in milliseconds.EXAT: Set an expiration time at a specific Unix timestamp in seconds.PXAT: Set an expiration time at a specific Unix timestamp in milliseconds.KEEPTTL: Keep the original TTL if the key already exists.
// Set a basic key-value pair
kv.set('username', 'john_doe');
// Set a key-value pair only if the key does not already exist (NX option)
kv.set('username', 'jane_doe', {NX: true});
// Get the existing value and set a new value for a key (GET option)
kv.set('username', 'mary_smith', {GET: true});
// Set a key-value pair with an expiration time in seconds (EX option)
kv.set('session_token', 'abc123', {EX: 3600});
// Get the value of an existing key
kv.get('username');