presidium-db-client-server 0.7.1 → 4.0.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.
Files changed (2) hide show
  1. package/README.md +21 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -100,6 +100,27 @@ for await (const postJson of postHt.reverseIterator()) {
100
100
  }
101
101
  ```
102
102
 
103
+ ## Load balance your distributed database
104
+ ```javascript
105
+ const DatabaseLoadBalancer = require("presidium/DatabaseLoadBalancer")
106
+
107
+ function hash(tableName, key, length) {
108
+ const value = `${tableName}${key}`
109
+ const digest = crypto.createHash("md5").update(value).digest()
110
+ const integerHash = digest.readUInt16BE(0)
111
+ const index = Math.floor(integerHash / 65535 * length)
112
+ return index
113
+ }
114
+
115
+ const loadBalancer = new DatabaseLoadBalancer(hash, {
116
+ serverIps: ["10.0.0.1:8080", "10.0.0.2:8080"],
117
+ })
118
+
119
+ loadBalancer.listen(6333, () => {
120
+ console.log("Database load balancer listening on port 6333")
121
+ })
122
+ ```
123
+
103
124
  ## Docs
104
125
  Coming soon.
105
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium-db-client-server",
3
- "version": "0.7.1",
3
+ "version": "4.0.0",
4
4
  "description": "Presidium DB client and server library",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",