Configs2026年7月16日·1 分钟阅读

node-redis — Official Redis Client for Node.js

High-performance Redis client for Node.js with TypeScript support, auto-pipelining, Lua scripting, and cluster/sentinel support.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Single
信任
信任等级:Established
入口
node-redis Overview
安全暂存命令
npx -y tokrepo@latest install d7dc01bf-8135-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

Introduction

node-redis is the official Redis client for Node.js, maintained by Redis Ltd. Version 4+ provides a modern async/await API with full TypeScript type definitions, automatic command pipelining, and support for Redis modules like RediSearch, RedisJSON, and RedisTimeSeries. It connects to standalone Redis, Sentinel, and Cluster deployments.

What node-redis Does

  • Connects to Redis standalone, Sentinel, and Cluster topologies
  • Executes all Redis commands via a fully typed async API
  • Pipelines commands automatically to reduce round-trip latency
  • Supports Pub/Sub, streams, transactions, and Lua scripting
  • Integrates with Redis modules for JSON, search, time-series, and graph operations

Architecture Overview

node-redis uses a single TCP connection per client (or a pool in cluster mode) and communicates via the RESP protocol. Commands are queued and flushed in batches using automatic pipelining, which groups multiple commands into a single network write. The client handles reconnection with configurable backoff, and in cluster mode it discovers the slot map and routes commands to the correct shard automatically.

Setup & Configuration

  • Install via npm install redis (includes TypeScript types)
  • Connect with createClient({ url: 'redis://localhost:6379' })
  • Enable auto-pipelining (on by default in v4+) for batched command execution
  • For Sentinel, use createClient({ sentinel: { ... } }) with master name and sentinels list
  • For Cluster, use createCluster({ rootNodes: [...] }) to connect to Redis Cluster

Key Features

  • Automatic pipelining batches commands for higher throughput
  • Full TypeScript type definitions for all Redis commands
  • Built-in support for Redis Cluster and Sentinel topologies
  • Pub/Sub with dedicated subscriber connections
  • Extensible module support for RediSearch, RedisJSON, and RedisTimeSeries

Comparison with Similar Tools

  • ioredis — mature community client with similar features, node-redis is the official library maintained by Redis Ltd
  • redis-py — official Python client, node-redis serves the same role for Node.js
  • Jedis — synchronous Java client, node-redis is async-first for the Node.js event loop
  • Lettuce — reactive Java client, node-redis uses async/await native to JavaScript

FAQ

Q: What changed between node-redis v3 and v4? A: v4 switched to async/await, added TypeScript types, introduced auto-pipelining, and added module support. The callback API was removed.

Q: How does auto-pipelining work? A: Commands issued in the same event loop tick are batched into a single network write, reducing round trips without requiring explicit pipeline calls.

Q: Can I use node-redis with Valkey or DragonflyDB? A: Yes. node-redis communicates via the standard RESP protocol, which Valkey and DragonflyDB implement.

Q: How do I handle connection drops? A: node-redis reconnects automatically with exponential backoff. Listen to the error and reconnecting events for visibility.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产