@eturino/ioredis-del-by-pattern

中文文档
3.0.1发布于 2025/01/22MITTypeScriptESM + CJS零依赖近 30 天下载 6400

ioredis util to delete keys by pattern on redis. Supports batches (pipeline) and lets the user decide to use del or unlink methods.

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Acknowledgements
  4. Development, Commits, versioning and publishing
  5. Commits and CHANGELOG
  6. Creating the first version
  7. Publish the Docs
  8. Generate a version

@eturino/ioredis-del-by-pattern

npm version Build Status Maintainability Test Coverage

TypeDoc generated docs in here

Github repo here

ioredis util to delete keys by pattern on redis. Supports batches (pipeline) and lets the user decide to use del or unlink methods.

It uses a scanStream in ioredis to gather the matched keys to remove.

Installation

yarn add @eturino/ioredis-del-by-pattern or npm install @eturino/ioredis-del-by-pattern.

Usage

The exported function redisDelByPattern() returns a promise with the number of keys deleted in total, using the given pattern and redis client.

import { redisDelByPattern } from "@eturino/ioredis-del-by-pattern";

const deletedKeysCount: number = await redisDelByPattern({
  pattern: "delete-with-this-prefix-*",
  redis // ioredis client
});

It supports the following params:

  • redis: redis client. (REQUIRED)
  • pattern: match in the redis scan stream. (REQUIRED)
  • deletionMethod: determines the usage of DEL or UNLINK commands (Unlink by default).
  • withPipeline: decide to use a pipeline to execute the commands or on each stream event (no pipeline by default).
  • pipelineBatchLimit: 100 by default, in effect if withPipeline is true.
  • enableLog: if true, actions will be logged using the given logFn.
  • logFn: function to execute to log events. Defaults to (console.log).
  • logWarnFn: function to execute to log events for warn. Defaults to (console.warn).
  • logPrefix: prefix to the logFn (defaults to "[REDIS-DEL-BY-PATTERN] ").
import { redisDelByPattern } from "@eturino/ioredis-del-by-pattern";

const deletedKeysCount: number = await redisDelByPattern({
  pattern: `${prefix}-delete-me*`,
  redis, // ioredis client
  withPipeline: true,
  deletionMethod: RedisDeletionMethod.unlink
});

Acknowledgements

The batched function implementation is heavily based on the article "Find and Delete multiple keys matching by a pattern in Redis: The right way " by Ankit Jain

Development, Commits, versioning and publishing

See documentation for development

See The Typescript-Starter docs.

Commits and CHANGELOG

For commits, you should use commitizen

yarn global add commitizen

#commit your changes:
git cz

As typescript-starter docs state:

This project is tooled for conventional changelog to make managing releases easier. See the standard-version documentation for more information on the workflow, or CHANGELOG.md for an example.

# bump package.json version, update CHANGELOG.md, git tag the release
yarn run version

You may find a tool like wip helpful for managing work in progress before you're ready to create a meaningful commit.

Creating the first version

Once you are ready to create the first version, run the following (note that reset is destructive and will remove all files not in the git repo from the directory).

# Reset the repo to the latest commit and build everything
yarn run reset && yarn run test && yarn run doc:html

# Then version it with standard-version options. e.g.:
# don't bump package.json version
yarn run version -- --first-release

# Other popular options include:

# PGP sign it:
# $ yarn run version -- --sign

# alpha release:
# $ yarn run version -- --prerelease alpha

And after that, remember to publish the docs.

And finally push the new tags to github and publish the package to npm.

# Push to git
git push --follow-tags origin master

# Publish to NPM (allowing public access, required if the package name is namespaced like `@somewhere/some-lib`)
yarn publish --access public

Publish the Docs

yarn run doc:html && yarn run doc:publish

This will generate the docs and publish them in github pages.

Generate a version

There is a single yarn command for preparing a new release. See One-step publish preparation script in TypeScript-Starter

# Prepare a standard release
yarn prepare-release

# Push to git
git push --follow-tags origin master

# Publish to NPM (allowing public access, required if the package name is namespaced like `@somewhere/some-lib`)
yarn publish --access public

版本与发布记录

@eturino/ioredis-del-by-pattern 共发布 10 个版本,首次发布于 2020/02/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.1latest2025/01/221.8 年前
3.0.02025/01/221.8 年前
2.0.12023/05/313 年前
2.0.02023/02/033 年前
1.1.02021/09/145 年前
1.0.42021/01/265 年前

关于 @eturino/ioredis-del-by-pattern 的常见问题

@eturino/ioredis-del-by-pattern 是什么?

ioredis util to delete keys by pattern on redis. Supports batches (pipeline) and lets the user decide to use del or unlink methods.

如何安装 @eturino/ioredis-del-by-pattern?

在项目目录运行 npm install @eturino/ioredis-del-by-pattern,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ioredis(^5.4.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@eturino/ioredis-del-by-pattern 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eturino/ioredis-del-by-pattern 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@eturino/ioredis-del-by-pattern 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@eturino/ioredis-del-by-pattern 可以商用吗?

@eturino/ioredis-del-by-pattern 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eturino/ioredis-del-by-pattern 的下载量有多少?

根据 npm 官方下载统计,@eturino/ioredis-del-by-pattern 在 2026/10/14 – 2026/11/12 这 30 天内被下载 6,400 次,日均约 213 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eturino/ioredis-del-by-pattern 还在维护吗?

最新版本 3.0.1 发布于 2025/01/22(1.8 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/02/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。