File size: 5,522 Bytes
330b6e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# Redis Setup Guide for Chat Agent

## Why Redis is Used

The chat agent uses Redis for several performance and scalability benefits:

1. **Session Caching** - Fast access to frequently used session data
2. **Chat History Caching** - Quick retrieval of recent messages
3. **Rate Limiting** - Distributed rate limiting across multiple app instances
4. **User Session Tracking** - Managing multiple sessions per user

## Error 10061 Explanation

**Error 10061 connecting to localhost:6379** means:
- Port 6379 is Redis's default port
- No Redis server is running on your machine
- The application can't connect to Redis for caching

## Installation Options

### Option 1: Windows Native Installation

1. **Download Redis for Windows:**
   - Visit: https://github.com/microsoftarchive/redis/releases
   - Download the latest `.msi` installer
   - Run the installer and follow the setup wizard

2. **Start Redis:**
   ```cmd

   # Redis should start automatically after installation

   # Or manually start it:

   redis-server

   ```

3. **Verify Installation:**
   ```cmd

   redis-cli ping

   # Should return: PONG

   ```

### Option 2: Using Chocolatey (Windows)

```cmd

# Install Chocolatey first if you don't have it

# Then install Redis:

choco install redis-64



# Start Redis

redis-server



# Test connection

redis-cli ping

```

### Option 3: Using Docker (Recommended)

```bash

# Pull and run Redis container

docker run -d -p 6379:6379 --name redis redis:alpine



# Verify it's running

docker ps



# Test connection

docker exec -it redis redis-cli ping

```

### Option 4: WSL/Linux

```bash

# Update package list

sudo apt update



# Install Redis

sudo apt install redis-server



# Start Redis service

sudo systemctl start redis-server



# Enable auto-start on boot

sudo systemctl enable redis-server



# Test connection

redis-cli ping

```

## Configuration

### Environment Variables

Create a `.env` file in your project root:

```env

# Redis Configuration

REDIS_URL=redis://localhost:6379/0

REDIS_HOST=localhost

REDIS_PORT=6379

REDIS_DB=0

REDIS_PASSWORD=



# For production with password:

# REDIS_URL=redis://:password@localhost:6379/0

# REDIS_PASSWORD=your-secure-password

```

### Testing Configuration

For testing without Redis, set:

```env

REDIS_URL=None

```

Or use the testing configuration which automatically disables Redis.

## Running Without Redis

The application is designed to work without Redis, but with reduced performance:

### What Works Without Redis:
- ✅ All API endpoints function normally
- ✅ Session management (database-only)
- ✅ Chat history (database-only)
- ✅ Language context management
- ✅ Authentication and authorization

### What's Affected Without Redis:
- ⚠️ **Performance**: Slower session and message retrieval
- ⚠️ **Rate Limiting**: Uses in-memory storage (not distributed)
- ⚠️ **Caching**: No caching layer, all requests hit the database
- ⚠️ **Scalability**: Cannot scale across multiple app instances

### Performance Impact:
- Session retrieval: ~50-100ms slower per request
- Chat history: ~100-200ms slower for large histories
- Rate limiting: Resets when app restarts

## Production Recommendations

### Redis Configuration for Production:

1. **Use a dedicated Redis instance**
2. **Enable password authentication**
3. **Configure persistence** (RDB + AOF)
4. **Set up monitoring**
5. **Use Redis Cluster** for high availability

### Example Production Config:

```env

# Production Redis with authentication

REDIS_URL=redis://:your-secure-password@redis-server:6379/0

REDIS_PASSWORD=your-secure-password



# Connection pool settings

REDIS_MAX_CONNECTIONS=20

REDIS_SOCKET_TIMEOUT=5

REDIS_SOCKET_CONNECT_TIMEOUT=5

```

## Troubleshooting

### Common Issues:

1. **"Connection refused" (Error 10061)**
   - Redis server is not running
   - Wrong host/port configuration
   - Firewall blocking the connection

2. **"Authentication failed"**
   - Wrong password in REDIS_URL

   - Redis configured with auth but no password provided



3. **"Connection timeout"**

   - Network issues

   - Redis server overloaded

   - Wrong host address



### Debug Commands:



```bash

# Check if Redis is running

redis-cli ping



# Check Redis info

redis-cli info



# Monitor Redis commands

redis-cli monitor



# Check specific database

redis-cli -n 0 keys "*"

```



## Development vs Production



### Development (Local):

```env

REDIS_URL=redis://localhost:6379/0
```



### Testing (No Redis):

```env

REDIS_URL=None

```

### Production (Managed Redis):
```env

REDIS_URL=redis://:password@your-redis-host:6379/0

```

## Cloud Redis Services

For production, consider managed Redis services:

- **AWS ElastiCache**
- **Google Cloud Memorystore**
- **Azure Cache for Redis**
- **Redis Cloud**
- **DigitalOcean Managed Redis**

These provide:
- Automatic backups
- High availability
- Monitoring and alerts
- Security and compliance
- Automatic scaling

## Summary

The **Error 10061** occurs because Redis is not installed or running. You have three options:

1. **Install Redis** (recommended for development/production)
2. **Use Docker** to run Redis (easiest setup)
3. **Run without Redis** (works but with performance impact)

The application gracefully handles Redis being unavailable and will continue to function using database-only operations.