@koala42/redis-highway 0.2.4 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -3
- package/README.md +0 -124
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koala42/redis-highway",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "High performance redis queue",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
"name": "David Stranava",
|
|
9
9
|
"url": "https://github.com/stranavad"
|
|
10
10
|
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"url": "https://github.com/Koala42/redis-highway",
|
|
13
|
+
"type": "github",
|
|
14
|
+
"directory": "packages/redis-highway"
|
|
15
|
+
},
|
|
11
16
|
"type": "commonjs",
|
|
12
17
|
"main": "dist/src/index.js",
|
|
13
18
|
"types": "dist/src/index.d.ts",
|
|
@@ -16,7 +21,8 @@
|
|
|
16
21
|
],
|
|
17
22
|
"scripts": {
|
|
18
23
|
"clean": "rimraf dist",
|
|
19
|
-
"test
|
|
24
|
+
"test": "vitest run test",
|
|
25
|
+
"test:all": "vitest run test",
|
|
20
26
|
"build": "npm run clean && tsc",
|
|
21
27
|
"prepublish": "npm run build"
|
|
22
28
|
},
|
|
@@ -36,4 +42,4 @@
|
|
|
36
42
|
"typescript": "^5.9.3",
|
|
37
43
|
"vitest": "^4.0.16"
|
|
38
44
|
}
|
|
39
|
-
}
|
|
45
|
+
}
|
package/README.md
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
# @koala42/redis-highway
|
|
2
|
-
|
|
3
|
-
High performance Redis stream-based queue for Node.js. Supports Redis single instances and Valkey single instances
|
|
4
|
-
|
|
5
|
-
## Missing features ATM
|
|
6
|
-
- Better gracefull shutdown handling
|
|
7
|
-
- In worker process functions expose more than just data: T like job id and current status
|
|
8
|
-
- Option to customize/enable/disable metrics
|
|
9
|
-
- Enable custom logger for workers and producers instead of console.logs
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## Roadmap
|
|
13
|
-
- Support redis cluster, that is probably possible only for job payloads and DLQ, since the stream is only one
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install @koala42/redis-highway
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
### Producer
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import { Redis } from 'ioredis';
|
|
27
|
-
import { Producer } from '@koala42/redis-highway';
|
|
28
|
-
|
|
29
|
-
const redis = new Redis();
|
|
30
|
-
const producer = new Producer(redis, 'my-stream');
|
|
31
|
-
|
|
32
|
-
// Send job
|
|
33
|
-
await producer.push(
|
|
34
|
-
JSON.stringify({ hello: 'world' }), // Message serialization is not done automatically
|
|
35
|
-
['group-A', 'group-B'] // Target specific consumer groups
|
|
36
|
-
);
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Worker
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { Redis } from 'ioredis';
|
|
43
|
-
import { Worker } from '@koala42/redis-highway';
|
|
44
|
-
|
|
45
|
-
class MyWorker extends Worker<T> {
|
|
46
|
-
async process(data: T) {
|
|
47
|
-
console.log('Processing:', data);
|
|
48
|
-
// throw new Error('fail'); // Automatic retry/DLQ logic
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const redis = new Redis();
|
|
53
|
-
const worker = new MyWorker(redis, 'group-A', 'my-stream');
|
|
54
|
-
|
|
55
|
-
await worker.start();
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Metrics
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
import { Metrics } from '@koala42/redis-highway';
|
|
62
|
-
|
|
63
|
-
const metrics = new Metrics(redis, 'my-stream');
|
|
64
|
-
|
|
65
|
-
// Prometheus format
|
|
66
|
-
const payload = await metrics.getPrometheusMetrics(['group-A']);
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Usage with NestJS
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
|
|
73
|
-
// Producer
|
|
74
|
-
@Injectable()
|
|
75
|
-
export class EntryService {
|
|
76
|
-
privater readonly producer: Producer;
|
|
77
|
-
|
|
78
|
-
constructor(){
|
|
79
|
-
this.producer = new Producer(
|
|
80
|
-
new Redis(...), // Or reuse existing ioredis connection
|
|
81
|
-
'my-stream'
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public async sth(): Promise<void>{
|
|
86
|
-
await producer.push(
|
|
87
|
-
JSON.stringify({ hello: 'world' }), // Message serialization is not done automatically
|
|
88
|
-
['group-A', 'group-B'] // Target specific consumer groups
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// Processor
|
|
95
|
-
@Injectable()
|
|
96
|
-
export class ProcessorService extends Worker<T> implements OnModuleInit, OnModuleDestroy {
|
|
97
|
-
constructor(){
|
|
98
|
-
super(
|
|
99
|
-
new Redis(...), // or reuse existing redis conn
|
|
100
|
-
'group-A',
|
|
101
|
-
'my-stream',
|
|
102
|
-
50 // concurrency
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async onModuleInit(): Promise<void>{
|
|
107
|
-
await this.start()
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
onModuleDestroy(){
|
|
111
|
-
this.stop()
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async process(data: T): Promise<void>{
|
|
115
|
-
console.log("Processing job", JSON.stringify(data))
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
````
|
|
119
|
-
|
|
120
|
-
## Features
|
|
121
|
-
- **Lightweight**: Uses light Lua scripts and pipelines wherever possible, making it highly concurrents for inserts and for processing as well, because of the reduced I/O load compared to BullMQ
|
|
122
|
-
- **Granular Retries**: If one group fails, only that group retries.
|
|
123
|
-
- **DLQ**: Dead Letter Queue support after max retries.
|
|
124
|
-
- **Metrics**: Throughput, Waiting, DLQ, Prometheus export.
|