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ivr using Rollup v2.79.2 and Terser v5.39.0.\n * Original file: /npm/@keyv/redis@4.4.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// src/index.ts\nimport EventEmitter from \"node:events\";\nimport {\n  createClient,\n  createCluster\n} from \"@redis/client\";\nimport { Keyv } from \"keyv\";\nimport calculateSlot from \"cluster-key-slot\";\nimport {\n  createClient as createClient2,\n  createCluster as createCluster2\n} from \"@redis/client\";\nimport {\n  Keyv as Keyv2\n} from \"keyv\";\nvar KeyvRedis = class extends EventEmitter {\n  _client = createClient();\n  _namespace;\n  _keyPrefixSeparator = \"::\";\n  _clearBatchSize = 1e3;\n  _useUnlink = true;\n  _noNamespaceAffectsAll = false;\n  /**\n   * KeyvRedis constructor.\n   * @param {string | RedisClientOptions | RedisClientType} [connect] How to connect to the Redis server. If string pass in the url, if object pass in the options, if RedisClient pass in the client.\n   * @param {KeyvRedisOptions} [options] Options for the adapter such as namespace, keyPrefixSeparator, and clearBatchSize.\n   */\n  constructor(connect, options) {\n    super();\n    if (connect) {\n      if (typeof connect === \"string\") {\n        this._client = createClient({ url: connect });\n      } else if (connect.connect !== void 0) {\n        this._client = this.isClientCluster(connect) ? connect : connect;\n      } else if (connect instanceof Object) {\n        this._client = connect.rootNodes === void 0 ? createClient(connect) : createCluster(connect);\n      }\n    }\n    this.setOptions(options);\n    this.initClient();\n  }\n  /**\n   * Get the Redis client.\n   */\n  get client() {\n    return this._client;\n  }\n  /**\n   * Set the Redis client.\n   */\n  set client(value) {\n    this._client = value;\n    this.initClient();\n  }\n  /**\n   * Get the options for the adapter.\n   */\n  get opts() {\n    let url = \"redis://localhost:6379\";\n    if (this._client.options) {\n      const redisUrl = this._client.options?.url;\n      if (redisUrl) {\n        url = redisUrl;\n      }\n    }\n    const results = {\n      namespace: this._namespace,\n      keyPrefixSeparator: this._keyPrefixSeparator,\n      clearBatchSize: this._clearBatchSize,\n      noNamespaceAffectsAll: this._noNamespaceAffectsAll,\n      dialect: \"redis\",\n      url\n    };\n    return results;\n  }\n  /**\n   * Set the options for the adapter.\n   */\n  set opts(options) {\n    this.setOptions(options);\n  }\n  /**\n   * Get the namespace for the adapter. If undefined, it will not use a namespace including keyPrefixing.\n   * @default undefined\n   */\n  get namespace() {\n    return this._namespace;\n  }\n  /**\n   * Set the namespace for the adapter. If undefined, it will not use a namespace including keyPrefixing.\n   */\n  set namespace(value) {\n    this._namespace = value;\n  }\n  /**\n   * Get the separator between the namespace and key.\n   * @default '::'\n   */\n  get keyPrefixSeparator() {\n    return this._keyPrefixSeparator;\n  }\n  /**\n   * Set the separator between the namespace and key.\n   */\n  set keyPrefixSeparator(value) {\n    this._keyPrefixSeparator = value;\n  }\n  /**\n   * Get the number of keys to delete in a single batch.\n   * @default 1000\n   */\n  get clearBatchSize() {\n    return this._clearBatchSize;\n  }\n  /**\n   * Set the number of keys to delete in a single batch.\n   */\n  set clearBatchSize(value) {\n    if (value > 0) {\n      this._clearBatchSize = value;\n    } else {\n      this.emit(\"error\", \"clearBatchSize must be greater than 0\");\n    }\n  }\n  /**\n   * Get if Unlink is used instead of Del for clearing keys. This is more performant but may not be supported by all Redis versions.\n   * @default true\n   */\n  get useUnlink() {\n    return this._useUnlink;\n  }\n  /**\n   * Set if Unlink is used instead of Del for clearing keys. This is more performant but may not be supported by all Redis versions.\n   */\n  set useUnlink(value) {\n    this._useUnlink = value;\n  }\n  /**\n   * Get if no namespace affects all keys.\n   * Whether to allow clearing all keys when no namespace is set.\n   * If set to true and no namespace is set, iterate() will return all keys.\n   * @default false\n   */\n  get noNamespaceAffectsAll() {\n    return this._noNamespaceAffectsAll;\n  }\n  /**\n   * Set if not namespace affects all keys.\n   */\n  set noNamespaceAffectsAll(value) {\n    this._noNamespaceAffectsAll = value;\n  }\n  /**\n   * Get the Redis URL used to connect to the server. This is used to get a connected client.\n   */\n  async getClient() {\n    try {\n      if (!this._client.isOpen) {\n        await this._client.connect();\n      }\n    } catch (error) {\n      this.emit(\"error\", error);\n    }\n    return this._client;\n  }\n  /**\n   * Set a key value pair in the store. TTL is in milliseconds.\n   * @param {string} key - the key to set\n   * @param {string} value - the value to set\n   * @param {number} [ttl] - the time to live in milliseconds\n   */\n  async set(key, value, ttl) {\n    const client = await this.getClient();\n    key = this.createKeyPrefix(key, this._namespace);\n    if (ttl) {\n      await client.set(key, value, { PX: ttl });\n    } else {\n      await client.set(key, value);\n    }\n  }\n  /**\n   * Will set many key value pairs in the store. TTL is in milliseconds. This will be done as a single transaction.\n   * @param {KeyvEntry[]} entries - the key value pairs to set with optional ttl\n   */\n  async setMany(entries) {\n    const client = await this.getClient();\n    const multi = client.multi();\n    for (const { key, value, ttl } of entries) {\n      const prefixedKey = this.createKeyPrefix(key, this._namespace);\n      if (ttl) {\n        multi.set(prefixedKey, value, { PX: ttl });\n      } else {\n        multi.set(prefixedKey, value);\n      }\n    }\n    await multi.exec();\n  }\n  /**\n   * Check if a key exists in the store.\n   * @param {string} key - the key to check\n   * @returns {Promise<boolean>} - true if the key exists, false if not\n   */\n  async has(key) {\n    const client = await this.getClient();\n    key = this.createKeyPrefix(key, this._namespace);\n    const exists = await client.exists(key);\n    return exists === 1;\n  }\n  /**\n   * Check if many keys exist in the store. This will be done as a single transaction.\n   * @param {Array<string>} keys - the keys to check\n   * @returns {Promise<Array<boolean>>} - array of booleans for each key if it exists\n   */\n  async hasMany(keys) {\n    const client = await this.getClient();\n    const multi = client.multi();\n    for (const key of keys) {\n      const prefixedKey = this.createKeyPrefix(key, this._namespace);\n      multi.exists(prefixedKey);\n    }\n    const results = await multi.exec();\n    return results.map((result) => result === 1);\n  }\n  /**\n   * Get a value from the store. If the key does not exist, it will return undefined.\n   * @param {string} key - the key to get\n   * @returns {Promise<string | undefined>} - the value or undefined if the key does not exist\n   */\n  async get(key) {\n    const client = await this.getClient();\n    key = this.createKeyPrefix(key, this._namespace);\n    const value = await client.get(key);\n    if (value === null) {\n      return void 0;\n    }\n    return value;\n  }\n  /**\n   * Get many values from the store. If a key does not exist, it will return undefined.\n   * @param {Array<string>} keys - the keys to get\n   * @returns {Promise<Array<string | undefined>>} - array of values or undefined if the key does not exist\n   */\n  async getMany(keys) {\n    if (keys.length === 0) {\n      return [];\n    }\n    keys = keys.map((key) => this.createKeyPrefix(key, this._namespace));\n    const values = await this.mget(keys);\n    return values;\n  }\n  /**\n   * Delete a key from the store.\n   * @param {string} key - the key to delete\n   * @returns {Promise<boolean>} - true if the key was deleted, false if not\n   */\n  async delete(key) {\n    const client = await this.getClient();\n    key = this.createKeyPrefix(key, this._namespace);\n    let deleted = 0;\n    deleted = await (this._useUnlink ? client.unlink(key) : client.del(key));\n    return deleted > 0;\n  }\n  /**\n   * Delete many keys from the store. This will be done as a single transaction.\n   * @param {Array<string>} keys - the keys to delete\n   * @returns {Promise<boolean>} - true if any key was deleted, false if not\n   */\n  async deleteMany(keys) {\n    let result = false;\n    const client = await this.getClient();\n    const multi = client.multi();\n    for (const key of keys) {\n      const prefixedKey = this.createKeyPrefix(key, this._namespace);\n      if (this._useUnlink) {\n        multi.unlink(prefixedKey);\n      } else {\n        multi.del(prefixedKey);\n      }\n    }\n    const results = await multi.exec();\n    for (const deleted of results) {\n      if (typeof deleted === \"number\" && deleted > 0) {\n        result = true;\n      }\n    }\n    return result;\n  }\n  /**\n   * Disconnect from the Redis server.\n   * @returns {Promise<void>}\n   * @param {boolean} [force] - it will send a quit command if false, otherwise it will send a disconnect command to forcefully disconnect.\n   * @see {@link https://github.com/redis/node-redis/tree/master/packages/redis#disconnecting}\n   */\n  async disconnect(force) {\n    if (this._client.isOpen) {\n      await (force ? this._client.disconnect() : this._client.quit());\n    }\n  }\n  /**\n   * Helper function to create a key with a namespace.\n   * @param {string} key - the key to prefix\n   * @param {string} namespace - the namespace to prefix the key with\n   * @returns {string} - the key with the namespace such as 'namespace::key'\n   */\n  createKeyPrefix(key, namespace) {\n    if (namespace) {\n      return `${namespace}${this._keyPrefixSeparator}${key}`;\n    }\n    return key;\n  }\n  /**\n   * Helper function to get a key without the namespace.\n   * @param {string} key - the key to remove the namespace from\n   * @param {string} namespace - the namespace to remove from the key\n   * @returns {string} - the key without the namespace such as 'key'\n   */\n  getKeyWithoutPrefix(key, namespace) {\n    if (namespace) {\n      return key.replace(`${namespace}${this._keyPrefixSeparator}`, \"\");\n    }\n    return key;\n  }\n  /**\n   * Is the client a cluster.\n   * @returns {boolean} - true if the client is a cluster, false if not\n   */\n  isCluster() {\n    return this.isClientCluster(this._client);\n  }\n  /**\n   * Get the master nodes in the cluster. If not a cluster, it will return the single client.\n   *\n   * @returns {Promise<RedisClientType[]>} - array of master nodes\n   */\n  async getMasterNodes() {\n    if (this.isCluster()) {\n      const cluster = await this.getClient();\n      return Promise.all(cluster.masters.map(async (main) => cluster.nodeClient(main)));\n    }\n    return [await this.getClient()];\n  }\n  /**\n   * Get an async iterator for the keys and values in the store. If a namespace is provided, it will only iterate over keys with that namespace.\n   * @param {string} [namespace] - the namespace to iterate over\n   * @returns {AsyncGenerator<[string, T | undefined], void, unknown>} - async iterator with key value pairs\n   */\n  async *iterator(namespace) {\n    const clients = await this.getMasterNodes();\n    for (const client of clients) {\n      const match = namespace ? `${namespace}${this._keyPrefixSeparator}*` : \"*\";\n      let cursor = \"0\";\n      do {\n        const result = await client.scan(Number.parseInt(cursor, 10), { MATCH: match, TYPE: \"string\" });\n        cursor = result.cursor.toString();\n        let { keys } = result;\n        if (!namespace && !this._noNamespaceAffectsAll) {\n          keys = keys.filter((key) => !key.includes(this._keyPrefixSeparator));\n        }\n        if (keys.length > 0) {\n          const values = await this.mget(keys);\n          for (const i of keys.keys()) {\n            const key = this.getKeyWithoutPrefix(keys[i], namespace);\n            const value = values[i];\n            yield [key, value];\n          }\n        }\n      } while (cursor !== \"0\");\n    }\n  }\n  /**\n   * Clear all keys in the store.\n   * IMPORTANT: this can cause performance issues if there are a large number of keys in the store and worse with clusters. Use with caution as not recommended for production.\n   * If a namespace is not set it will clear all keys with no prefix.\n   * If a namespace is set it will clear all keys with that namespace.\n   * @returns {Promise<void>}\n   */\n  async clear() {\n    try {\n      const clients = await this.getMasterNodes();\n      await Promise.all(clients.map(async (client) => {\n        if (!this._namespace && this._noNamespaceAffectsAll) {\n          await client.flushDb();\n          return;\n        }\n        let cursor = \"0\";\n        const batchSize = this._clearBatchSize;\n        const match = this._namespace ? `${this._namespace}${this._keyPrefixSeparator}*` : \"*\";\n        const deletePromises = [];\n        do {\n          const result = await client.scan(Number.parseInt(cursor, 10), { MATCH: match, COUNT: batchSize, TYPE: \"string\" });\n          cursor = result.cursor.toString();\n          let { keys } = result;\n          if (keys.length === 0) {\n            continue;\n          }\n          if (!this._namespace) {\n            keys = keys.filter((key) => !key.includes(this._keyPrefixSeparator));\n          }\n          deletePromises.push(this.clearWithClusterSupport(keys));\n        } while (cursor !== \"0\");\n        await Promise.all(deletePromises);\n      }));\n    } catch (error) {\n      this.emit(\"error\", error);\n    }\n  }\n  /**\n   * Get many keys. If the instance is a cluster, it will do multiple MGET calls\n   * by separating the keys by slot to solve the CROSS-SLOT restriction.\n   */\n  async mget(keys) {\n    const slotMap = this.getSlotMap(keys);\n    const valueMap = /* @__PURE__ */ new Map();\n    await Promise.all(Array.from(slotMap.entries(), async ([slot, keys2]) => {\n      const client = await this.getSlotMaster(slot);\n      const values = await client.mGet(keys2);\n      for (const [index, value] of values.entries()) {\n        valueMap.set(keys2[index], value ?? void 0);\n      }\n    }));\n    return keys.map((key) => valueMap.get(key));\n  }\n  /**\n   * Clear all keys in the store with a specific namespace. If the instance is a cluster, it will clear all keys\n   * by separating the keys by slot to solve the CROSS-SLOT restriction.\n   */\n  async clearWithClusterSupport(keys) {\n    if (keys.length > 0) {\n      const slotMap = this.getSlotMap(keys);\n      await Promise.all(Array.from(slotMap.entries(), async ([slot, keys2]) => {\n        const client = await this.getSlotMaster(slot);\n        return this._useUnlink ? client.unlink(keys2) : client.del(keys2);\n      }));\n    }\n  }\n  /**\n   * Returns the master node client for a given slot or the instance's client if it's not a cluster.\n   */\n  async getSlotMaster(slot) {\n    const connection = await this.getClient();\n    if (this.isCluster()) {\n      const cluster = connection;\n      const mainNode = cluster.slots[slot].master;\n      return cluster.nodeClient(mainNode);\n    }\n    return connection;\n  }\n  /**\n   * Group keys by their slot.\n   *\n   * @param {string[]} keys - the keys to group\n   * @returns {Map<number, string[]>} - map of slot to keys\n   */\n  getSlotMap(keys) {\n    const slotMap = /* @__PURE__ */ new Map();\n    if (this.isCluster()) {\n      for (const key of keys) {\n        const slot = calculateSlot(key);\n        const slotKeys = slotMap.get(slot) ?? [];\n        slotKeys.push(key);\n        slotMap.set(slot, slotKeys);\n      }\n    } else {\n      slotMap.set(0, keys);\n    }\n    return slotMap;\n  }\n  isClientCluster(client) {\n    if (client.options === void 0 && client.scan === void 0) {\n      return true;\n    }\n    return false;\n  }\n  setOptions(options) {\n    if (!options) {\n      return;\n    }\n    if (options.namespace) {\n      this._namespace = options.namespace;\n    }\n    if (options.keyPrefixSeparator !== void 0) {\n      this._keyPrefixSeparator = options.keyPrefixSeparator;\n    }\n    if (options.clearBatchSize !== void 0 && options.clearBatchSize > 0) {\n      this._clearBatchSize = options.clearBatchSize;\n    }\n    if (options.useUnlink !== void 0) {\n      this._useUnlink = options.useUnlink;\n    }\n    if (options.noNamespaceAffectsAll !== void 0) {\n      this._noNamespaceAffectsAll = options.noNamespaceAffectsAll;\n    }\n  }\n  initClient() {\n    this._client.on(\"error\", (error) => {\n      this.emit(\"error\", error);\n    });\n  }\n};\nfunction createKeyv(connect, options) {\n  connect ??= \"redis://localhost:6379\";\n  const adapter = new KeyvRedis(connect, options);\n  const keyv = new Keyv({ store: adapter, namespace: options?.namespace, useKeyPrefix: false });\n  return keyv;\n}\nexport {\n  Keyv2 as Keyv,\n  createClient2 as createClient,\n  createCluster2 as createCluster,\n  createKeyv,\n  KeyvRedis as default\n};\n"]}