(key, amount = 1)
| 113 | } |
| 114 | |
| 115 | async decrement(key, amount = 1) { |
| 116 | if (this.useFallback) { |
| 117 | logger.debug(`[DEGRADED] Decrementing in memory: ${key}`); |
| 118 | } |
| 119 | if (this.db.decrement) { |
| 120 | return this.db.decrement(key, amount); |
| 121 | } |
| 122 | const current = await this.db.get(key, 0); |
| 123 | const newValue = current - amount; |
| 124 | await this.db.set(key, newValue); |
| 125 | return newValue; |
| 126 | } |
| 127 | |
| 128 | isDegraded() { |
| 129 | return this.useFallback; |