@tillstack/cache-node 0.2.1 → 0.4.0
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/README.md +65 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @tillstack/cache-node
|
|
2
|
+
|
|
3
|
+
[TillCache](https://tilldev.dev/tillcache) for Node.js: managed key-value storage, durable queues and pub/sub over one HTTPS endpoint and one token, with no Redis cluster to run. The KV methods mirror ioredis.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @tillstack/cache-node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Connect
|
|
12
|
+
|
|
13
|
+
Copy the connection string from the dashboard into `TILLCACHE_URL=tillcache://tc_…@cache.tilldev.dev`, then:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createClient } from '@tillstack/cache-node'
|
|
17
|
+
|
|
18
|
+
const cache = createClient() // reads TILLCACHE_URL
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## KV
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
await cache.set('session:abc', token, { ex: 3600, nx: true })
|
|
25
|
+
await cache.incr('views')
|
|
26
|
+
await cache.hset('user:42', { name: 'Ada', plan: 'pro' })
|
|
27
|
+
await cache.sadd('seen:today', userId)
|
|
28
|
+
await cache.zincrby('leaderboard', 25, 'ada')
|
|
29
|
+
const top = await cache.zrevrange('leaderboard', 0, 9, 'WITHSCORES')
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Queues
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
await cache.queue('emails').push({ to: 'ada@example.com' })
|
|
36
|
+
|
|
37
|
+
await cache.queue<{ to: string }>('emails').consume(async (msg) => {
|
|
38
|
+
await sendEmail(msg.body.to) // throw to retry; acked on success
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const { messages } = await cache.queue('emails').deadLetters()
|
|
42
|
+
await cache.queue('emails').replay({ ids: messages.map((m) => m.id) })
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
After 5 failed deliveries a message moves to the dead-letter queue, where it stays for 14 days.
|
|
46
|
+
|
|
47
|
+
## Pub/sub
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
await cache.publish('presence', { user: 'ada', status: 'online' })
|
|
51
|
+
|
|
52
|
+
const stop = new AbortController()
|
|
53
|
+
cache.subscribe('presence', (msg) => console.log(msg.message), { signal: stop.signal })
|
|
54
|
+
cache.subscribe('orders.*', (msg) => console.log(msg.channel, msg.message), { signal: stop.signal })
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The token only goes over https; plain http is allowed for localhost only.
|
|
58
|
+
|
|
59
|
+
## Docs
|
|
60
|
+
|
|
61
|
+
https://tilldev.dev/docs/tillcache/quickstart
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tillstack/cache-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "TillCache client for Node.js — managed KV, durable queues and pub/sub over one HTTPS endpoint, with a drop-in ioredis-compatible surface.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@tillstack/cache-core": "^0.
|
|
27
|
+
"@tillstack/cache-core": "^0.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.0.0",
|