Skip to content

Commit 820f85e

Browse files
committed
Fix mock Redis server to handle proper Redis handshake protocol
1 parent c2d71f7 commit 820f85e

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/app.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,37 @@ describe('Redis Proxy API', () => {
2020
port: targetPort,
2121
socket: {
2222
data(socket, data) {
23-
// Simple Redis protocol responses with storage
23+
// Handle Redis protocol commands properly
2424
const command = data.toString();
25+
console.log('Mock Redis received:', command.replace(/\r\n/g, '\\r\\n'));
2526

26-
if (command.includes('FOO')) {
27+
// Handle HELLO command (Redis 6+ handshake)
28+
if (command.includes('HELLO')) {
29+
// Return Redis server info for HELLO command
30+
socket.write('*7\r\n$6\r\nserver\r\n$5\r\nredis\r\n$7\r\nversion\r\n$5\r\n7.2.0\r\n$5\r\nproto\r\n:3\r\n$2\r\nid\r\n:1\r\n');
31+
}
32+
// Handle AUTH command
33+
else if (command.includes('AUTH')) {
34+
socket.write('+OK\r\n');
35+
}
36+
// Handle PING command
37+
else if (command.includes('PING')) {
38+
socket.write('+PONG\r\n');
39+
}
40+
// Handle FOO command (our test command)
41+
else if (command.includes('FOO')) {
2742
socket.write('+BAR\r\n');
28-
} else {
43+
}
44+
// Handle SELECT command (database selection)
45+
else if (command.includes('SELECT')) {
46+
socket.write('+OK\r\n');
47+
}
48+
// Handle INFO command
49+
else if (command.includes('INFO')) {
50+
socket.write('$23\r\n# Server\r\nredis_version:7.2.0\r\n');
51+
}
52+
// Default response for any other command
53+
else {
2954
socket.write('+OK\r\n');
3055
}
3156
},

0 commit comments

Comments
 (0)