Skip to content

Commit db326b7

Browse files
committed
docs: update readme and regenerate docs
1 parent d84497b commit db326b7

File tree

6 files changed

+170
-43
lines changed

6 files changed

+170
-43
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
An [async iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) that emits redis stream entries.
44
Requires Redis 5 or greater.
55

6+
![release](https://badgen.net/github/release/calebboyd/redis-x-stream)
7+
![license](https://badgen.net/badge/license/MIT/blue)
8+
9+
![test](https://github.com/calebboyd/redis-x-stream/actions/workflows/test.yml/badge.svg
10+
)
611
## Getting Started
712

813
```javascript
@@ -48,6 +53,7 @@ const stream = new RedisStream({
4853
//eg. k8s StatefulSet hostname. or Cloud Foundry instance index
4954
consumer: 'tpc_' + process.env.SOME_ORDINAL_IDENTIFIER,
5055
block: Infinity,
56+
count: 10
5157
ackOnIterate: true,
5258
deleteOnAck: true,
5359
})
@@ -61,11 +67,11 @@ control.on('shutdown', async () => {
6167
await stream.drain()
6268
})
6369

64-
65-
const semaphore = new Semaphore(10)
70+
const lock = new Semaphore(11)
71+
const release = lock.release.bind(lock)
6672
for await (const [streamName, [id, keyvals]] of stream) {
67-
await semaphore.acquire()
68-
tryTask(id, keyvals)
73+
await lock.acquire()
74+
tryTask(id, keyvals).finally(release)
6975
}
7076
```
7177

docs/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ redis-x-stream / [Exports](modules.md)
55
An [async iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) that emits redis stream entries.
66
Requires Redis 5 or greater.
77

8+
![release](https://badgen.net/github/release/calebboyd/redis-x-stream)
9+
![license](https://badgen.net/badge/license/MIT/blue)
10+
11+
![test](https://github.com/calebboyd/redis-x-stream/actions/workflows/test.yml/badge.svg
12+
)
813
## Getting Started
914

1015
```javascript
@@ -33,3 +38,41 @@ async function populate(stream, count) {
3338
## Usage
3439

3540
See the [API Docs](docs/classes/RedisStream.md#constructor) for available options.
41+
42+
## Advanced Usage
43+
44+
### Task Processing
45+
46+
If you have a cluster of processes reading redis stream entries you likely want to utilize redis consumer groups
47+
48+
A task processing application may look like the following:
49+
50+
```javascript
51+
const control = { /* some control event emitter */ }
52+
const stream = new RedisStream({
53+
streams: ['my-stream'],
54+
group: ' ',
55+
//eg. k8s StatefulSet hostname. or Cloud Foundry instance index
56+
consumer: 'tpc_' + process.env.SOME_ORDINAL_IDENTIFIER,
57+
block: Infinity,
58+
count: 10
59+
ackOnIterate: true,
60+
deleteOnAck: true,
61+
})
62+
63+
control.on('new-source', (streamName) => {
64+
//Add an additional source stream to a blocked stream.
65+
stream.addStream(streamName)
66+
})
67+
control.on('shutdown', async () => {
68+
//drain will process all claimed entries (the PEL) and stop iteration
69+
await stream.drain()
70+
})
71+
72+
const lock = new Semaphore(11)
73+
const release = lock.release.bind(lock)
74+
for await (const [streamName, [id, keyvals]] of stream) {
75+
await lock.acquire()
76+
tryTask(id, keyvals).finally(release)
77+
}
78+
```

docs/classes/RedisStream.md

Lines changed: 96 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212

1313
- [ackOnIterate](RedisStream.md#ackoniterate)
1414
- [block](RedisStream.md#block)
15+
- [blocked](RedisStream.md#blocked)
1516
- [buffers](RedisStream.md#buffers)
1617
- [client](RedisStream.md#client)
1718
- [consumer](RedisStream.md#consumer)
1819
- [control](RedisStream.md#control)
1920
- [count](RedisStream.md#count)
2021
- [deleteOnAck](RedisStream.md#deleteonack)
2122
- [done](RedisStream.md#done)
23+
- [draining](RedisStream.md#draining)
2224
- [first](RedisStream.md#first)
2325
- [group](RedisStream.md#group)
2426
- [noack](RedisStream.md#noack)
@@ -29,6 +31,9 @@
2931

3032
- [[asyncIterator]](RedisStream.md#[asynciterator])
3133
- [ack](RedisStream.md#ack)
34+
- [addStream](RedisStream.md#addstream)
35+
- [drain](RedisStream.md#drain)
36+
- [end](RedisStream.md#end)
3237
- [quit](RedisStream.md#quit)
3338
- [return](RedisStream.md#return)
3439

@@ -47,7 +52,7 @@
4752

4853
#### Defined in
4954

50-
[stream.ts:75](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L75)
55+
[stream.ts:82](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L82)
5156

5257
## Properties
5358

@@ -57,7 +62,7 @@
5762

5863
#### Defined in
5964

60-
[stream.ts:43](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L43)
65+
[stream.ts:44](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L44)
6166

6267
___
6368

@@ -67,7 +72,17 @@ ___
6772

6873
#### Defined in
6974

70-
[stream.ts:39](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L39)
75+
[stream.ts:40](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L40)
76+
77+
___
78+
79+
### blocked
80+
81+
`Readonly` **blocked**: `boolean` = `false`
82+
83+
#### Defined in
84+
85+
[stream.ts:34](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L34)
7186

7287
___
7388

@@ -77,7 +92,7 @@ ___
7792

7893
#### Defined in
7994

80-
[stream.ts:40](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L40)
95+
[stream.ts:41](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L41)
8196

8297
___
8398

@@ -87,7 +102,7 @@ ___
87102

88103
#### Defined in
89104

90-
[stream.ts:30](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L30)
105+
[stream.ts:30](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L30)
91106

92107
___
93108

@@ -97,7 +112,7 @@ ___
97112

98113
#### Defined in
99114

100-
[stream.ts:33](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L33)
115+
[stream.ts:33](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L33)
101116

102117
___
103118

@@ -107,7 +122,7 @@ ___
107122

108123
#### Defined in
109124

110-
[stream.ts:31](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L31)
125+
[stream.ts:31](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L31)
111126

112127
___
113128

@@ -117,7 +132,7 @@ ___
117132

118133
#### Defined in
119134

120-
[stream.ts:37](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L37)
135+
[stream.ts:38](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L38)
121136

122137
___
123138

@@ -127,7 +142,7 @@ ___
127142

128143
#### Defined in
129144

130-
[stream.ts:44](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L44)
145+
[stream.ts:45](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L45)
131146

132147
___
133148

@@ -139,7 +154,17 @@ Flag for iterable state
139154

140155
#### Defined in
141156

142-
[stream.ts:56](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L56)
157+
[stream.ts:57](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L57)
158+
159+
___
160+
161+
### draining
162+
163+
**draining**: `boolean` = `false`
164+
165+
#### Defined in
166+
167+
[stream.ts:59](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L59)
143168

144169
___
145170

@@ -149,7 +174,7 @@ ___
149174

150175
#### Defined in
151176

152-
[stream.ts:57](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L57)
177+
[stream.ts:58](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L58)
153178

154179
___
155180

@@ -159,7 +184,7 @@ ___
159184

160185
#### Defined in
161186

162-
[stream.ts:32](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L32)
187+
[stream.ts:32](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L32)
163188

164189
___
165190

@@ -169,7 +194,7 @@ ___
169194

170195
#### Defined in
171196

172-
[stream.ts:38](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L38)
197+
[stream.ts:39](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L39)
173198

174199
___
175200

@@ -183,7 +208,7 @@ Acks waiting to be sent on either:
183208

184209
#### Defined in
185210

186-
[stream.ts:52](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L52)
211+
[stream.ts:53](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L53)
187212

188213
___
189214

@@ -193,7 +218,7 @@ ___
193218

194219
#### Defined in
195220

196-
[stream.ts:36](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L36)
221+
[stream.ts:37](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L37)
197222

198223
## Methods
199224

@@ -207,7 +232,7 @@ ___
207232

208233
#### Defined in
209234

210-
[stream.ts:145](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L145)
235+
[stream.ts:160](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L160)
211236

212237
___
213238

@@ -228,7 +253,59 @@ ___
228253

229254
#### Defined in
230255

231-
[stream.ts:204](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L204)
256+
[stream.ts:226](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L226)
257+
258+
___
259+
260+
### addStream
261+
262+
**addStream**(`streamName`): `Promise`<`void`\>
263+
264+
#### Parameters
265+
266+
| Name | Type |
267+
| :------ | :------ |
268+
| `streamName` | `string` |
269+
270+
#### Returns
271+
272+
`Promise`<`void`\>
273+
274+
#### Defined in
275+
276+
[stream.ts:250](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L250)
277+
278+
___
279+
280+
### drain
281+
282+
**drain**(): `Promise`<`void`\>
283+
284+
Iterate through remaining items in the PEL and exit
285+
286+
#### Returns
287+
288+
`Promise`<`void`\>
289+
290+
#### Defined in
291+
292+
[stream.ts:258](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L258)
293+
294+
___
295+
296+
### end
297+
298+
**end**(): `Promise`<`void`\>
299+
300+
Immediately stop processing entries
301+
302+
#### Returns
303+
304+
`Promise`<`void`\>
305+
306+
#### Defined in
307+
308+
[stream.ts:266](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L266)
232309

233310
___
234311

@@ -242,7 +319,7 @@ ___
242319

243320
#### Defined in
244321

245-
[stream.ts:190](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L190)
322+
[stream.ts:212](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L212)
246323

247324
___
248325

@@ -256,4 +333,4 @@ ___
256333

257334
#### Defined in
258335

259-
[stream.ts:214](https://github.com/calebboyd/redis-x-stream/blob/52317a3/src/stream.ts#L214)
336+
[stream.ts:277](https://github.com/calebboyd/redis-x-stream/blob/d84497b/src/stream.ts#L277)

0 commit comments

Comments
 (0)