npm package: @franknitty69/n8n-nodes-redis-advanced
Description: Advanced Redis node for n8n with comprehensive operations including json, pub/sub, lists, sets, hashes, and TTL support
Author: Ahmed Agbabiaka
Latest version: 0.0.7

# n8n-nodes-redis-advanced

This is an n8n community node that provides comprehensive Redis integration with advanced operations for your n8n workflows.

Redis Advanced extends the basic Redis functionality with 35+ operations including atomic operations, bulk operations, advanced data structures (sets, sorted sets, hashes), TTL management, Lua scripting, and pub/sub capabilities.

[n8n](https://n8n.io/) is a [fair-code licensed](https://docs.n8n.io/reference/license/) workflow automation platform.

[Installation](#installation)  
[Operations](#operations)  
[Credentials](#credentials)  
[Compatibility](#compatibility)  
[Usage](#usage)  
[Development](#development)  
[Testing](#testing)  
[Resources](#resources)  
[Version History](#version-history)

## Installation

Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) in the n8n community nodes documentation.

### Quick Install

1. Open your n8n instance
2. Go to **Settings** → **Community Nodes**
3. Enter the package name: `@franknitty69/n8n-nodes-redis-advanced`
4. Click **Install**
5. Restart n8n

### Manual Installation

```bash
npm install @franknitty69/n8n-nodes-redis-advanced
```

## Operations

Redis Enhanced provides 37 comprehensive operations organized by category:

### 🔑 **Basic Operations**

- **Get** - Retrieve values from Redis with automatic type detection
- **Set** - Store values with atomic lock support (NX/XX modes) and TTL
- **Delete** - Remove keys from Redis
- **Exists** - Check if one or more keys exist
- **Info** - Get Redis server information and statistics

### 📦 **Bulk Operations**

- **Multi Get (MGET)** - Retrieve multiple keys in a single operation
- **Multi Set (MSET)** - Set multiple key-value pairs atomically
- **Scan** - Production-safe key iteration with pattern matching
- **Keys** - Find keys matching patterns (with optional value retrieval)

### 🔢 **String Operations**

- **Increment (INCR)** - Atomic counter operations with optional TTL
- **Append** - Append values to existing strings
- **String Length** - Get the length of string values
- **Get Set** - Atomically set new value and return old value

### 📋 **List Operations**

- **Push** - Add elements to lists (left/right)
- **Pop** - Remove elements from lists (left/right)
- **Blocking Pop Left (BLPOP)** - Blocking pop from list start
- **Blocking Pop Right (BRPOP)** - Blocking pop from list end
- **List Length** - Get the number of elements in a list

### 🎯 **Set Operations**

- **Set Add (SADD)** - Add members to sets
- **Set Remove (SREM)** - Remove members from sets
- **Set Is Member (SISMEMBER)** - Check set membership
- **Set Cardinality (SCARD)** - Get the number of set members

#### 🎯 **JSON Operations**

- **JSON Get (JSON.get)**: Retrieve JSON values from Redis with path support
- **JSON Set (JSON.set)**: Store JSON values with atomic lock support (NX/XX modes) and TTL

### 📊 **Sorted Set Operations**

- **Sorted Set Add (ZADD)** - Add scored members to sorted sets
- **Sorted Set Range (ZRANGE)** - Get ranges with optional scores
- **Sorted Set Remove (ZREM)** - Remove members from sorted sets
- **Sorted Set Cardinality (ZCARD)** - Get sorted set size

### 🗂️ **Hash Operations**

- **Hash Length (HLEN)** - Get number of hash fields
- **Hash Keys (HKEYS)** - Get all field names
- **Hash Values (HVALS)** - Get all hash values
- **Hash Exists (HEXISTS)** - Check if hash field exists

### ⏰ **TTL Operations**

- **TTL** - Get time-to-live for keys
- **Persist** - Remove expiration from keys
- **Expire At** - Set expiration at specific timestamp

### 🚀 **Advanced Operations**

- **Eval** - Execute Lua scripts with key/argument support
- **Publish** - Publish messages to Redis channels

### 🔒 **Enhanced Features**

- **Atomic Operations** - NX (set if not exists) and XX (set if exists) modes
- **Bulk Processing** - Space-separated input parsing for multiple keys/values
- **Type Safety** - Automatic type detection and conversion
- **Error Handling** - Comprehensive error handling with continue-on-fail support
- **Production Ready** - Optimized for high-performance production use

## Credentials

To use Redis Enhanced, you need to set up Redis credentials in n8n:

### Prerequisites

- A Redis server (local, cloud, or managed service like AWS ElastiCache, Redis Cloud, etc.)
- Network connectivity from n8n to your Redis instance

### Authentication Setup

1. In n8n, go to **Credentials** → **Create New**
2. Search for **Redis Enhanced**
3. Configure the connection:
   - **Host**: Your Redis server hostname or IP
   - **Port**: Redis port (default: 6379)
   - **Database**: Database number (default: 0)
   - **Password**: Redis password (if AUTH is enabled)
   - **User**: Redis username (for Redis 6+ ACL)
   - **SSL**: Enable for TLS connections

### Supported Authentication Methods

- **No Authentication** - For development/local Redis instances
- **Password Authentication** - Traditional Redis AUTH
- **Username/Password** - Redis 6+ ACL with user accounts
- **TLS/SSL** - Encrypted connections for production deployments

## Compatibility

- **Minimum n8n version**: 1.0.0+
- **Redis versions**: 3.0+ (tested up to Redis 7.x)
- **Node.js**: 20.15+
- **Tested with**: n8n 1.x, Redis 6.x, Redis 7.x

### Known Compatibility

- ✅ **n8n Cloud**: Fully compatible
- ✅ **Self-hosted n8n**: All versions 1.0+
- ✅ **Docker deployments**: Tested and verified
- ✅ **Redis Cloud**: Compatible with all major providers
- ✅ **AWS ElastiCache**: Full compatibility
- ✅ **Redis Sentinel**: Supported
- ✅ **Redis Cluster**: Basic operations supported

## Usage

### Basic Example: Caching API Responses

```yaml
# Workflow: Cache expensive API calls
1. HTTP Request (API call)
2. Redis Enhanced (SET with TTL)
   - Operation: Set
   - Key: api:cache:{{$json.id}}
   - Value: {{$json}}
   - TTL: 300 seconds
```

### Advanced Example: Atomic Counters

```yaml
# Workflow: Rate limiting with atomic counters
1. Redis Enhanced (SET with NX)
   - Operation: Set
   - Key: rate_limit:{{$json.user_id}}
   - Value: 1
   - Set Mode: Set If Not Exists (NX)
   - TTL: 3600 seconds
2. If key already exists → Rate limit exceeded
```

### Bulk Operations Example

```yaml
# Workflow: Bulk data processing
1. Redis Enhanced (MGET)
   - Operation: Multi Get
   - Keys: user:1 user:2 user:3 user:4
2. Redis Enhanced (MSET)
   - Operation: Multi Set
   - Key-Value Pairs: updated:1 true updated:2 true
```

### Production Tips

- Use **SCAN** instead of **KEYS** for production key iteration
- Leverage **atomic operations** (NX/XX) for race condition prevention
- Set appropriate **TTL values** for cache invalidation
- Use **bulk operations** (MGET/MSET) for better performance
- Monitor operations with **INFO** for production insights

## Development

### Prerequisites

- Node.js 20.15+
- npm or yarn
- Redis server for testing

### Setup

```bash
git clone https://github.com/vicenterusso/n8n-nodes-redis-enhanced.git
cd n8n-nodes-redis-enhanced
npm install
```

### Build

```bash
npm run build     # Build the node
npm run dev       # Build in watch mode
npm run lint      # Check code quality
npm run lintfix   # Auto-fix linting issues
```

## Testing

The project includes comprehensive test coverage with 31+ tests covering all operations:

```bash
npm test              # Run all tests
npm run test:watch    # Run tests in watch mode
npm run test:coverage # Run with coverage report
```

### Test Coverage

- **31 passing tests** across all operations
- **42.97% code coverage** with detailed branch coverage
- **Infrastructure testing** (connection, client setup)
- **Operation testing** (all 35 operations)
- **Error handling** (continue-on-fail scenarios)
- **Parameter validation** (input validation)

### Test Categories

- ✅ **Connection Tests** - Redis client setup and connectivity
- ✅ **Basic Operations** - GET, SET, DELETE, EXISTS, INFO
- ✅ **Bulk Operations** - MGET, MSET, SCAN, KEYS
- ✅ **Advanced Operations** - Atomic operations, TTL, Lua scripts
- ✅ **Error Handling** - Comprehensive error scenarios
- ✅ **Type Safety** - Input/output type validation

## Resources

- [n8n community nodes documentation](https://docs.n8n.io/integrations/#community-nodes)
- [Redis Documentation](https://redis.io/documentation)
- [Redis Commands Reference](https://redis.io/commands)
- [n8n Workflow Templates](https://n8n.io/workflows)
- [Project Repository](https://github.com/vicenterusso/n8n-nodes-redis-enhanced)

## Version History

### v0.1.0 (Current)

- **Initial Release** with 35 Redis operations
- **Comprehensive Testing** - 31 tests, 42.97% coverage
- **Production Ready** - Atomic operations, bulk processing, error handling
- **Enhanced Features** - NX/XX modes, TTL management, Lua scripting
- **Full Documentation** - Complete API coverage and examples

#### Features Added:

- ✅ Basic operations (GET, SET, DELETE, EXISTS, INFO)
- ✅ Bulk operations (MGET, MSET, SCAN, KEYS)
- ✅ String operations (INCR, APPEND, STRLEN, GETSET)
- ✅ List operations (PUSH, POP, BLPOP, BRPOP, LLEN)
- ✅ Set operations (SADD, SREM, SISMEMBER, SCARD)
- ✅ Sorted set operations (ZADD, ZRANGE, ZREM, ZCARD)
- ✅ Hash operations (HLEN, HKEYS, HVALS, HEXISTS)
- ✅ TTL operations (TTL, PERSIST, EXPIREAT)
- ✅ Advanced operations (EVAL, PUBLISH)
- ✅ Atomic lock support (NX/XX modes)
- ✅ Comprehensive error handling
- ✅ Production deployment tools

---

**Author**: Ahmed Agbabiaka (franknitty69@gmail.com) forked from Vicente Russo Neto (vicente.russo@gmail.com)  
**License**: MIT  
**Repository**: https://github.com/franknitty69/n8n-nodes-redis-advanced