export class UsageMeter {
    constructor(redis) {
        this.redis = redis;
    }
    async record(tokenId) {
        await this.redis.hincrby("usage", tokenId, 1);
    }
    async readAndReset() {
        const result = await this.redis.eval(`
      local result = redis.call('HGETALL', KEYS[1])
      redis.call('DEL', KEYS[1])
      return result
      `, 1, "usage");
        const usage = {};
        for (let i = 0; i < result.length; i += 2) {
            const key = result[i];
            const value = Number(result[i + 1]);
            usage[key] = value;
        }
        return usage;
    }
}
//# sourceMappingURL=usage-meter.js.map