Key-Value State Operations
The State provider has key-value operations for storing state.
Set a Value
Using a key, you can store a value for retrieval later.
Method Signature
Setting a Value
session = vcr.createSession()
state = State(session)
await state.set('obj', { 'foo': bar })
Increment a Value
If you have stored an integer you can increment it by a specified amount.
Method Signature
Incrementing a Value
await state.increment('count', 1)
Decrement a Value
If you have stored an integer you can decrement it by a specified amount.
Method Signature
Decrementing a Value
await state.decrement('count', 1)
Get a Value
Using a key, you can fetch a value previously stored.
Method Signature
Getting a Value
object = await state.get('obj')
Expire a Value
Using a key, you can expire a value previously stored after a specified number of seconds.
Method Signature
Types
expire supports a set of options(EXPIRE_OPTION):
NX: Set expiry only when the key has no expiryXX: Set expiry only when the key has an existing expiryGT: Set expiry only when the new expiry is greater than the current oneLT: Set expiry only when the new expiry is less than the current one
Expiring a Value
await state.expire('obj', 200)
Delete a Value
Using a key, you can delete a value previously stored.
Method Signature
Deleting a Value
await state.delete('obj')