memcache 1.3.0 → 1.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 +163 -1
- package/dist/index.cjs +1522 -1175
- package/dist/index.d.cts +266 -134
- package/dist/index.d.ts +266 -134
- package/dist/index.js +1521 -1175
- package/package.json +24 -9
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[<img src="https://jaredwray.com/images/memcache.svg" alt="Memcache Logo" align="center">](https://memcachejs.org)
|
|
1
|
+
[<img src="https://jaredwray.com/images/memcache.svg" width="80%" height="80%" align="center" alt="Memcache Logo" align="center">](https://memcachejs.org)
|
|
2
2
|
|
|
3
3
|
[](https://codecov.io/gh/jaredwray/memcache)
|
|
4
4
|
[](https://github.com/jaredwray/memcache/actions/workflows/tests.yaml)
|
|
@@ -59,6 +59,12 @@ Nodejs Memcache Client
|
|
|
59
59
|
- [Per-Node SASL Configuration](#per-node-sasl-configuration)
|
|
60
60
|
- [Authentication Events](#authentication-events)
|
|
61
61
|
- [Server Configuration](#server-configuration)
|
|
62
|
+
- [Auto Discovery](#auto-discovery)
|
|
63
|
+
- [Enabling Auto Discovery](#enabling-auto-discovery)
|
|
64
|
+
- [Auto Discovery Options](#auto-discovery-options)
|
|
65
|
+
- [Auto Discovery Events](#auto-discovery-events)
|
|
66
|
+
- [Legacy Command Support](#legacy-command-support)
|
|
67
|
+
- [IPv6 Support](#ipv6-support)
|
|
62
68
|
- [Contributing](#contributing)
|
|
63
69
|
- [License and Copyright](#license-and-copyright)
|
|
64
70
|
|
|
@@ -198,6 +204,7 @@ const client = new Memcache({
|
|
|
198
204
|
- `retryDelay?: number` - Base delay in milliseconds between retries (default: 100)
|
|
199
205
|
- `retryBackoff?: RetryBackoffFunction` - Function to calculate backoff delay (default: fixed delay)
|
|
200
206
|
- `retryOnlyIdempotent?: boolean` - Only retry commands marked as idempotent (default: true)
|
|
207
|
+
- `autoDiscover?: AutoDiscoverOptions` - AWS ElastiCache Auto Discovery configuration (see [Auto Discovery](#auto-discovery))
|
|
201
208
|
|
|
202
209
|
## Properties
|
|
203
210
|
|
|
@@ -404,6 +411,9 @@ client.on('miss', (key) => {
|
|
|
404
411
|
- `quit` - Emitted when quit command is sent
|
|
405
412
|
- `warn` - Emitted for warning messages
|
|
406
413
|
- `info` - Emitted for informational messages
|
|
414
|
+
- `autoDiscover` - Emitted on initial auto discovery with the cluster config
|
|
415
|
+
- `autoDiscoverUpdate` - Emitted when auto discovery detects a topology change
|
|
416
|
+
- `autoDiscoverError` - Emitted when auto discovery encounters an error
|
|
407
417
|
|
|
408
418
|
## Hooks
|
|
409
419
|
|
|
@@ -877,6 +887,158 @@ To use SASL authentication, your memcached server must be configured with SASL s
|
|
|
877
887
|
|
|
878
888
|
For more details, see the [memcached SASL documentation](https://github.com/memcached/memcached/wiki/SASLHowto).
|
|
879
889
|
|
|
890
|
+
# Auto Discovery
|
|
891
|
+
|
|
892
|
+
The Memcache client supports AWS ElastiCache Auto Discovery, which automatically detects cluster topology changes and adds or removes nodes as needed. When enabled, the client connects to a configuration endpoint, retrieves the current list of cache nodes, and periodically polls for changes.
|
|
893
|
+
|
|
894
|
+
## Enabling Auto Discovery
|
|
895
|
+
|
|
896
|
+
```javascript
|
|
897
|
+
import { Memcache } from 'memcache';
|
|
898
|
+
|
|
899
|
+
const client = new Memcache({
|
|
900
|
+
nodes: [],
|
|
901
|
+
autoDiscover: {
|
|
902
|
+
enabled: true,
|
|
903
|
+
configEndpoint: 'my-cluster.cfg.use1.cache.amazonaws.com:11211',
|
|
904
|
+
},
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
await client.connect();
|
|
908
|
+
// The client automatically discovers and connects to all cluster nodes
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
If you omit `configEndpoint`, the first node in the `nodes` array is used as the configuration endpoint:
|
|
912
|
+
|
|
913
|
+
```javascript
|
|
914
|
+
const client = new Memcache({
|
|
915
|
+
nodes: ['my-cluster.cfg.use1.cache.amazonaws.com:11211'],
|
|
916
|
+
autoDiscover: {
|
|
917
|
+
enabled: true,
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
## Auto Discovery Options
|
|
923
|
+
|
|
924
|
+
The `autoDiscover` option accepts an object with the following properties:
|
|
925
|
+
|
|
926
|
+
- `enabled: boolean` - Enable auto discovery of cluster nodes (required)
|
|
927
|
+
- `pollingInterval?: number` - How often to poll for topology changes, in milliseconds (default: 60000)
|
|
928
|
+
- `configEndpoint?: string` - The configuration endpoint to use for discovery. This is typically the `.cfg` endpoint from ElastiCache. If not specified, the first node in the `nodes` array will be used
|
|
929
|
+
- `useLegacyCommand?: boolean` - Use the legacy `get AmazonElastiCache:cluster` command instead of `config get cluster` (default: false)
|
|
930
|
+
|
|
931
|
+
## Auto Discovery Events
|
|
932
|
+
|
|
933
|
+
The client emits events during the auto discovery lifecycle:
|
|
934
|
+
|
|
935
|
+
```javascript
|
|
936
|
+
const client = new Memcache({
|
|
937
|
+
nodes: [],
|
|
938
|
+
autoDiscover: {
|
|
939
|
+
enabled: true,
|
|
940
|
+
configEndpoint: 'my-cluster.cfg.use1.cache.amazonaws.com:11211',
|
|
941
|
+
},
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
// Emitted on initial discovery with the full cluster config
|
|
945
|
+
client.on('autoDiscover', (config) => {
|
|
946
|
+
console.log('Discovered nodes:', config.nodes);
|
|
947
|
+
console.log('Config version:', config.version);
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
// Emitted when polling detects a topology change
|
|
951
|
+
client.on('autoDiscoverUpdate', (config) => {
|
|
952
|
+
console.log('Cluster topology changed:', config.nodes);
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
// Emitted when discovery encounters an error (non-fatal, retries on next poll)
|
|
956
|
+
client.on('autoDiscoverError', (error) => {
|
|
957
|
+
console.error('Discovery error:', error.message);
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
await client.connect();
|
|
961
|
+
```
|
|
962
|
+
|
|
963
|
+
## Legacy Command Support
|
|
964
|
+
|
|
965
|
+
For ElastiCache engine versions older than 1.4.14, use the legacy discovery command:
|
|
966
|
+
|
|
967
|
+
```javascript
|
|
968
|
+
const client = new Memcache({
|
|
969
|
+
nodes: [],
|
|
970
|
+
autoDiscover: {
|
|
971
|
+
enabled: true,
|
|
972
|
+
configEndpoint: 'my-cluster.cfg.use1.cache.amazonaws.com:11211',
|
|
973
|
+
useLegacyCommand: true, // Uses 'get AmazonElastiCache:cluster' instead of 'config get cluster'
|
|
974
|
+
},
|
|
975
|
+
});
|
|
976
|
+
```
|
|
977
|
+
|
|
978
|
+
# IPv6 Support
|
|
979
|
+
|
|
980
|
+
The Memcache client fully supports IPv6 addresses using standard bracket notation in URIs.
|
|
981
|
+
|
|
982
|
+
## Connecting to IPv6 Nodes
|
|
983
|
+
|
|
984
|
+
```javascript
|
|
985
|
+
import { Memcache } from 'memcache';
|
|
986
|
+
|
|
987
|
+
// IPv6 loopback
|
|
988
|
+
const client = new Memcache('[::1]:11211');
|
|
989
|
+
|
|
990
|
+
// Multiple IPv6 nodes
|
|
991
|
+
const client = new Memcache({
|
|
992
|
+
nodes: [
|
|
993
|
+
'[::1]:11211',
|
|
994
|
+
'[2001:db8::1]:11211',
|
|
995
|
+
'memcache://[2001:db8::2]:11212',
|
|
996
|
+
],
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
await client.connect();
|
|
1000
|
+
```
|
|
1001
|
+
|
|
1002
|
+
## IPv6 in Auto Discovery
|
|
1003
|
+
|
|
1004
|
+
When auto discovery returns IPv6 node addresses, the client automatically brackets them for correct URI handling:
|
|
1005
|
+
|
|
1006
|
+
```javascript
|
|
1007
|
+
const client = new Memcache({
|
|
1008
|
+
nodes: [],
|
|
1009
|
+
autoDiscover: {
|
|
1010
|
+
enabled: true,
|
|
1011
|
+
configEndpoint: '[2001:db8::1]:11211',
|
|
1012
|
+
},
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
await client.connect();
|
|
1016
|
+
// Discovered IPv6 nodes are added as [host]:port automatically
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
## IPv6 Node IDs
|
|
1020
|
+
|
|
1021
|
+
Node IDs for IPv6 addresses use bracket notation to avoid ambiguity:
|
|
1022
|
+
|
|
1023
|
+
```javascript
|
|
1024
|
+
const client = new Memcache({
|
|
1025
|
+
nodes: ['[::1]:11211', '[2001:db8::1]:11212'],
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
console.log(client.nodeIds);
|
|
1029
|
+
// ['[::1]:11211', '[2001:db8::1]:11212']
|
|
1030
|
+
```
|
|
1031
|
+
|
|
1032
|
+
# Benchmarks
|
|
1033
|
+
|
|
1034
|
+
These are provided to show a simple benchmark against current libraries. This is not robust but it is something we update regularly to make sure we are keeping performant.
|
|
1035
|
+
|
|
1036
|
+
| name | summary | ops/sec | time/op | margin | samples |
|
|
1037
|
+
|------------------------------|:---------:|----------:|----------:|:--------:|----------:|
|
|
1038
|
+
| memcache set/get (v1.4.0) | 🥇 | 3K | 350µs | ±0.19% | 10K |
|
|
1039
|
+
| memcached set/get (v2.2.2) | -2.9% | 3K | 361µs | ±0.16% | 10K |
|
|
1040
|
+
| memjs set/get (v1.3.2) | -12% | 3K | 398µs | ±0.17% | 10K |
|
|
1041
|
+
|
|
880
1042
|
# Contributing
|
|
881
1043
|
|
|
882
1044
|
Please read our [Contributing Guidelines](./CONTRIBUTING.md) and also our [Code of Conduct](./CODE_OF_CONDUCT.md).
|