* Increments a numeric value. Raises an error when underlying value is not a number. * * @param key - The key or key path to increment * @param steps - Number of steps to increment (default: 1) * * @example * store.increment('page_views') // Increments by 1 * store.increment
(key: string | string[], steps: number = 1)
| 211 | * store.increment('score', 10) // Increments by 10 |
| 212 | */ |
| 213 | increment(key: string | string[], steps: number = 1): void { |
| 214 | const value = this.get(key, 0) |
| 215 | if (typeof value !== 'number') { |
| 216 | throw new RuntimeException(`Cannot increment "${key}". Existing value is not a number`) |
| 217 | } |
| 218 | |
| 219 | this.set(key, value + steps) |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Decrements a numeric value. Raises an error when underlying value is not a number. |