@heady/redis-client 1.0.0 → 1.0.1
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 +6 -22
- package/dist/redisClient.d.ts +1 -0
- package/dist/redisClient.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
|
-

|
|
6
6
|
|
|
7
7
|
**Redis Client** is a lightweight, type-safe wrapper for [ioredis](https://github.com/luin/ioredis). It solves the problem of scaling Redis infrastructure by automatically routing **Write** operations to a Primary node and **Read** operations to Replica nodes.
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
## ✨ Features
|
|
23
23
|
|
|
24
|
-
* **Automatic Traffic Splitting:** Writes (`set`, `del`, `expire`) are sent to the Primary; Reads (`get`, `scan`, `hget`) are sent to Replicas.
|
|
24
|
+
* **Automatic Traffic Splitting:** Writes (`set`, `del`, `expire`) are sent to the Primary; Reads (`get`, `scan`, `hget`, `keys`) are sent to Replicas.
|
|
25
25
|
* **Type Safety:** Built with TypeScript, providing full IntelliSense and type checking out of the box.
|
|
26
26
|
* **Performance:** Offloads expensive read operations (like `SCAN`) from your Master node to prevent blocking critical write traffic.
|
|
27
27
|
* **Flexible Access:** Exposes the underlying `ioredis` instances if you need to run custom or unsupported commands.
|
|
@@ -40,17 +40,18 @@ Before you begin, ensure you have met the following requirements:
|
|
|
40
40
|
|
|
41
41
|
1. **Install the package and the peer dependency:**
|
|
42
42
|
```bash
|
|
43
|
-
npm install redis-client
|
|
43
|
+
npm install @heady/redis-client
|
|
44
|
+
```
|
|
44
45
|
|
|
45
46
|
---
|
|
46
47
|
|
|
47
48
|
## 💡 Usage
|
|
48
49
|
|
|
49
50
|
``` typescript
|
|
50
|
-
import {
|
|
51
|
+
import { RedisClient } from '@heady/redis-client';
|
|
51
52
|
|
|
52
53
|
// 1. Initialize with separate endpoints
|
|
53
|
-
const redis = new
|
|
54
|
+
const redis = new RedisClient({
|
|
54
55
|
primary: {
|
|
55
56
|
host: 'primary-node.redis.aws.internal',
|
|
56
57
|
port: 6379,
|
|
@@ -128,23 +129,6 @@ Expected Output:
|
|
|
128
129
|
✓ get() should call replica node
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
## 🤝 Contributing
|
|
132
|
-
|
|
133
|
-
Contributions are always welcome! Please follow these steps:
|
|
134
|
-
|
|
135
|
-
Fork the project.
|
|
136
|
-
|
|
137
|
-
Create your feature branch (git checkout -b feature/NewFeature).
|
|
138
|
-
|
|
139
|
-
Commit your changes (git commit -m 'Add some NewFeature').
|
|
140
|
-
|
|
141
|
-
Run tests to ensure no regressions (npm test).
|
|
142
|
-
|
|
143
|
-
Push to the branch.
|
|
144
|
-
|
|
145
|
-
Open a Pull Request.
|
|
146
|
-
|
|
147
|
-
|
|
148
132
|
## 📜 License
|
|
149
133
|
|
|
150
134
|
This project is licensed under the MIT License - see the LICENSE file for details.
|
package/dist/redisClient.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class RedisClient {
|
|
|
22
22
|
hget(key: string, field: string): Promise<string | null>;
|
|
23
23
|
hgetall(key: string): Promise<Record<string, string>>;
|
|
24
24
|
scan(cursor: string, matchPattern: string, count?: number): Promise<[string, string[]]>;
|
|
25
|
+
keys(pattern: string): Promise<string[]>;
|
|
25
26
|
/**
|
|
26
27
|
* -------------------------
|
|
27
28
|
* UTILITIES
|
package/dist/redisClient.js
CHANGED
|
@@ -52,6 +52,9 @@ class RedisClient {
|
|
|
52
52
|
async scan(cursor, matchPattern, count = 100) {
|
|
53
53
|
return this.replica.scan(cursor, "MATCH", matchPattern, "COUNT", count);
|
|
54
54
|
}
|
|
55
|
+
async keys(pattern) {
|
|
56
|
+
return this.replica.keys(pattern);
|
|
57
|
+
}
|
|
55
58
|
/**
|
|
56
59
|
* -------------------------
|
|
57
60
|
* UTILITIES
|