@derhuerst/redis-stream

中文文档
2.0.1发布于 2020/06/04(Apache-2.0 AND Prosperity-3.0.0)TypeScriptCommonJS近 30 天下载 5425

Redis 5 Streams as readable & writable Node streams. Plus a CLI.

原始使用文档
文档目录10 节
  1. Installation
  2. Command line usage
  3. Usage with JavaScript
  4. Writing to a Redis Stream
  5. Reading from a Redis Stream
  6. API
  7. createWriter(redis, streamName)
  8. createReader(redis, streamName, opt = {})
  9. License
  10. Contributing

redis-stream

Redis 5 Streams as readable & writable Node streams. Plus a command line interface.

npm version build status Prosperity/Apache license minimum Node.js version chat with me on Gitter support me via GitHub Sponsors

Installation

npm install @derhuerst/redis-stream

Command line usage

Usage:
    write-into-redis-stream <stream-name>
Examples:
    echo '{"user": "jane", "text": "hey!"}' | write-into-redis-stream chat-msgs
Usage:
    read-from-redis-stream <stream-name> [--history] [--live [--waitTimoout <ms>]] [--limit <n>]
Options:
    --live             Wait for newly added items? Default: true
    --waitTimeout  -t  How long to wait for newly added items. Default: Infinity
    --history          Read all past items from the stream? Default: false
    --limit        -l  Maximum number of items to read. Default: Infinity
Examples:
    read-from-redis-stream chat-msgs --live --limit 1000

Usage with JavaScript

Writing to a Redis Stream

const {createClient} = require('redis')
const createWriter = require('@derhuerst/redis-stream/writer')

const redis = createClient()
const writer = createWriter(redis, 'some-stream-name')
writer.once('finish', () => redis.quit())
writer.on('error', console.error)

writer.write({foo: 'bar'})
writer.end({hey: 'there!'})

Reading from a Redis Stream

const {createClient} = require('redis')
const createReader = require('@derhuerst/redis-stream/reader')

const redis = createClient()
const reader = createReader(redis, 'some-stream-name')
reader.on('data', console.log)
reader.on('error', console.error)

API

createWriter(redis, streamName)

Returns a readable stream in object mode.

createReader(redis, streamName, opt = {})

Returns a readable stream in object mode. opt may be an object with the following entries:

  • live: Wait for newly added items? Default: true
  • waitTimeout: How long to wait for newly added items. Default: Infinity
  • history: Read all past items from the stream? Default: false
  • limit: Maximum number of items to read. Default: Infinity

License

This project is dual-licensed: My contributions are licensed under the Prosperity Public License, contributions of other people are licensed as Apache 2.0.

This license allows you to use and share this software for noncommercial purposes for free and to try this software for commercial purposes for thirty days.

Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, doesn’t count as use for a commercial purpose.

Buy a commercial license or read more about why I sell private licenses for my projects.

Contributing

If you have a question or need support using redis-stream, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.

By contributing, you agree to release your modifications under the Apache 2.0 license.

版本与发布记录

@derhuerst/redis-stream 共发布 5 个版本,首次发布于 2019/05/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.1latest2020/06/046 年前
2.0.02020/05/176 年前
1.1.12020/05/176 年前
1.1.02019/10/027 年前
1.0.02019/05/287 年前

关于 @derhuerst/redis-stream 的常见问题

@derhuerst/redis-stream 是什么?

Redis 5 Streams as readable & writable Node streams. Plus a CLI.

如何安装 @derhuerst/redis-stream?

在项目目录运行 npm install @derhuerst/redis-stream,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 read-from-redis-stream、write-into-redis-stream,可以用 npx read-from-redis-stream 直接运行。

@derhuerst/redis-stream 支持 TypeScript 吗?

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

@derhuerst/redis-stream 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@derhuerst/redis-stream 需要什么版本的 Node.js?

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

@derhuerst/redis-stream 可以商用吗?

@derhuerst/redis-stream 使用 (Apache-2.0 AND Prosperity-3.0.0) 许可。声明的许可为 (Apache-2.0 AND Prosperity-3.0.0),请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@derhuerst/redis-stream 的下载量有多少?

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

@derhuerst/redis-stream 还在维护吗?

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