Skip to content

Commit 5f3d9f9

Browse files
committed
Expand README with quickstart, usage, and code examples
1 parent b7c173a commit 5f3d9f9

File tree

1 file changed

+97
-4
lines changed

1 file changed

+97
-4
lines changed

README.md

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,101 @@
44

55
A Redis protocol proxy with HTTP API for response injection.
66

7+
## Quickstart
8+
9+
Transparently proxy Redis connections while injecting custom RESP responses via REST API.
10+
11+
```
12+
+-------------+ RESP +-------------+ RESP +-------------+
13+
| Client App |<----------->| RESP Proxy |<----------->| Redis Server|
14+
+-------------+ +-------------+ +-------------+
15+
^
16+
|
17+
HTTP REST API
18+
(inject responses)
19+
```
20+
21+
### 30-Second Setup
22+
23+
```bash
24+
# Start proxy container ( the rest api will be running port 3000 by default)
25+
docker run -d \
26+
-p 6379:6379 -p 3000:3000 \
27+
-e TARGET_HOST=your-redis-host \
28+
-e TARGET_PORT=6380 \
29+
resp-proxy
30+
```
31+
32+
### Inject Custom RESP3 Push Notification
33+
34+
RESP3 Push notification: `>4\r\n$6\r\nMOVING\r\n:1\r\n:2\r\n$6\r\nhost:3\r\n`
35+
36+
**cURL Example:**
37+
```bash
38+
curl -X POST "http://localhost:3000/send-to-all-clients?encoding=raw" \
39+
--data-binary ">4\r\n\$6\r\nMOVING\r\n:1\r\n:2\r\n\$6\r\nhost:3\r\n"
40+
```
41+
42+
**TypeScript Example:**
43+
```typescript
44+
const response = await fetch('http://localhost:3000/send-to-all-clients?encoding=raw', {
45+
method: 'POST',
46+
body: '>4\r\n$6\r\nMOVING\r\n:1\r\n:2\r\n$6\r\nhost:3\r\n'
47+
});
48+
49+
const result = await response.text();
50+
console.log(result.includes('"success":true') ? 'Injected' : 'Failed');
51+
```
52+
53+
**Go Example:**
54+
```go
55+
package main
56+
57+
import (
58+
"io"
59+
"net/http"
60+
"strings"
61+
)
62+
63+
func main() {
64+
payload := strings.NewReader(">4\r\n$6\r\nMOVING\r\n:1\r\n:2\r\n$6\r\nhost:3\r\n")
65+
resp, _ := http.Post("http://localhost:3000/send-to-all-clients?encoding=raw", "", payload)
66+
defer resp.Body.Close()
67+
68+
body, _ := io.ReadAll(resp.Body)
69+
if strings.Contains(string(body), `"success":true`) {
70+
println("Injected")
71+
}
72+
}
73+
```
74+
75+
**Java Example:**
76+
```java
77+
import java.net.http.*;
78+
import java.net.URI;
79+
80+
public class RespProxyClient {
81+
public static void main(String[] args) throws Exception {
82+
var client = HttpClient.newHttpClient();
83+
var request = HttpRequest.newBuilder()
84+
.uri(URI.create("http://localhost:3000/send-to-all-clients?encoding=raw"))
85+
.POST(HttpRequest.BodyPublishers.ofString(
86+
">4\r\n$6\r\nMOVING\r\n:1\r\n:2\r\n$6\r\nhost:3\r\n"))
87+
.build();
88+
89+
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
90+
91+
if (response.body().contains("\"success\":true")) {
92+
System.out.println("Injected");
93+
}
94+
}
95+
}
96+
```
97+
98+
Key Endpoints: `POST /send-to-client/{id}`, `POST /send-to-all-clients`, `GET /connections`, `GET /stats`
99+
100+
---
101+
7102
## Features
8103

9104
- **Redis Transparent Protocol Proxy**: Forwards Redis connections from clients to target Redis servers
@@ -31,8 +126,6 @@ The easiest way to get started is with Docker :
31126
docker build -t resp-proxy .
32127
```
33128

34-
35-
36129
```bash
37130
# Run with Docker - connects to Redis on host
38131
docker run -d \
@@ -41,11 +134,11 @@ docker run -d \
41134
-e TARGET_HOST=host.docker.internal \ #<-- redis server host ( the proxy target )
42135
-e TARGET_PORT=6380 \ # redis server port
43136
-e LISTEN_PORT=6379 \ # proxy listen port
44-
-e API_PORT = 3000 \ # rest api port
137+
-e API_PORT = 3000 \ # rest api port
45138
resp-proxy
46139
```
47140

48-
### Local Development
141+
### Local Development
49142

50143
```bash
51144
# Install dependencies

0 commit comments

Comments
 (0)