BlueForge Docs

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

NameTypeRequiredNotes
key
stringyesRedis key name
by
numbernoIncrement amount (default 1)
ttl
numbernoTTL 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

ErrorCondition
ApiError
API request failed
NetworkError
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}