Key Value Store
KV store provides a persistent way to keep track of state for things like counters
Functions
setText
Function (key: string, value: string) => Promise<void>
Store a text value in the key value store
Argument | Type | Description |
---|---|---|
key | string | The key to store the value under |
value | string | The text value to store |
getText
Function (key: string, defaultValue?: string) => Promise<string | null>
Get a text value from the key value store
Argument | Type | Description |
---|---|---|
key | string | The key the value is stored under |
defaultValue Optional | string | Optional default value to use if the key is not present |
Present key:
Missing key:
Missing key with default:
remove
Function (key: string) => Promise<void>
Remove a key from the key value store
Argument | Type | Description |
---|---|---|
key | string | The key to remove |
setNumber
Function (key: string, value: number) => Promise<void>
Store a number value in the key value store
Argument | Type | Description |
---|---|---|
key | string | The key to store the value under |
value | number | The number value to store |
getNumber
Function (key: string, defaultValue?: number) => Promise<number | null>
Get a number value from the key value store
Argument | Type | Description |
---|---|---|
key | string | The key the value is stored under |
defaultValue Optional | number | Optional default value to use if the key is not present |
Present key:
Missing key:
Missing key with default:
setArray
Function <T>(key: string, value: T[]) => Promise<void>
Store an array value in the key value store
Argument | Type | Description |
---|---|---|
key | string | The key to store the value under |
value | T[] | The array value to store |
getArray
Function <T>(key: string, defaultValue?: T[]) => Promise<T[] | null>
Get an array value from the key value store
Argument | Type | Description |
---|---|---|
key | string | The key the value is stored under |
defaultValue Optional | T[] | Optional default value to use if the key is not present |
Present key:
Missing key:
Missing key with default:
setObject
Function <T>(key: string, value: T) => Promise<void>
Store an object value in the key value store
Argument | Type | Description |
---|---|---|
key | string | The key to store the value under |
value | T | The array value to store |
getObject
Function <T>(key: string, defaultValue?: T) => Promise<T | null>
Get an object value from the key value store
Argument | Type | Description |
---|---|---|
key | string | The key the value is stored under |
defaultValue Optional | number | Optional default value to use if the key is not present |
Present key:
Missing key:
Missing key with default:
createCounter
Function (key: string) => Counter
Get an object value from the key value store
Argument | Type | Description |
---|---|---|
key | string | The key the value is stored under |
Present key:
Classes
Counter
Helper for making a simple counter. Useful for making a counter for a specific thing (i.e times you’ve won)
get
Method (this: Counter) => Promise<number>
Get the current value of the counter. Will return zero for newly created counters
set
Method (this: Counter, value: number) => Promise<void>
Sets the current value of the counter
Argument | Type | Description |
---|---|---|
value | number | The new value for the counter |
increase
Method (this: Counter, amount?: number) => Promise<void>
Increase the counter
Argument | Type | Description |
---|---|---|
amount Optional | number | Amount to increase the counter by (Default: 1) |
By a specific amount:
decrease
Method (this: Counter, amount?: number) => Promise<void>
Decrease the counter
Argument | Type | Description |
---|---|---|
amount Optional | number | Amount to decrease the counter by (Default: 1) |
By a specific amount: