# 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. ## Install Save in your project root: # node-redis — Official Redis Client for Node.js ## Quick Use ```bash npm install redis ``` ```javascript import { createClient } from 'redis'; const client = createClient(); await client.connect(); await client.set('key', 'value'); const value = await client.get('key'); console.log(value); // 'value' await client.disconnect(); ``` ## 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 - https://github.com/redis/node-redis - https://redis.io/docs/clients/nodejs/ --- Source: https://tokrepo.com/en/workflows/asset-d7dc01bf Author: AI Open Source