client.redis.incr
Increment a RedisOS key's numeric value.
Signature
class Client {
redis: {
incr(key: string, opts?: { by?: number; ttl?: number }): Promise<number>
}
}
Parameters
| Name | Type | Required | Notes |
|---|---|---|---|
| string | yes | Redis key name |
| number | no | Increment amount (default 1) |
| number | no | TTL in seconds (set on first creation) |
Returns
The new value after increment.
Examples
const count = await bf.redis.incr('page:visits', { by: 1 })
console.log(`Visit #${count}`)
Throws
| Error | Condition |
|---|---|
| API request failed |
| Network issue |
Pitfalls
- Non-numeric values — incrementing a key that holds a non-numeric value returns an error
- Missing key — if the key doesn't exist, it's created with value 0 before incrementing
See also
{auto-injected}
Tested against
{auto-injected}