@valkey/valkey-glide 2.3.1 → 2.4.0-rc2

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.
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CompressionBackend = void 0;
7
+ exports.validateCompressionConfiguration = validateCompressionConfiguration;
8
+ exports.compressionConfigToProtobuf = compressionConfigToProtobuf;
9
+ const Errors_1 = require("./Errors");
10
+ /**
11
+ * Compression backend to use for automatic value compression.
12
+ */
13
+ var CompressionBackend;
14
+ (function (CompressionBackend) {
15
+ /** Use zstd compression backend. */
16
+ CompressionBackend[CompressionBackend["ZSTD"] = 0] = "ZSTD";
17
+ /** Use lz4 compression backend. */
18
+ CompressionBackend[CompressionBackend["LZ4"] = 1] = "LZ4";
19
+ })(CompressionBackend || (exports.CompressionBackend = CompressionBackend = {}));
20
+ /** Minimum allowed value for minCompressionSize (header size + 1). */
21
+ const MIN_COMPRESSED_SIZE = 6;
22
+ /** Default minimum size in bytes for values to be compressed. */
23
+ const DEFAULT_MIN_COMPRESSION_SIZE = 64;
24
+ /**
25
+ * Validates a CompressionConfiguration and throws ConfigurationError if invalid.
26
+ * @internal
27
+ */
28
+ function validateCompressionConfiguration(config) {
29
+ const minSize = config.minCompressionSize ?? DEFAULT_MIN_COMPRESSION_SIZE;
30
+ if (minSize < MIN_COMPRESSED_SIZE) {
31
+ throw new Errors_1.ConfigurationError(`minCompressionSize must be at least ${MIN_COMPRESSED_SIZE} bytes`);
32
+ }
33
+ if (config.compressionLevel !== undefined &&
34
+ !Number.isInteger(config.compressionLevel)) {
35
+ throw new Errors_1.ConfigurationError("compressionLevel must be an integer");
36
+ }
37
+ if (config.maxDecompressedSize !== undefined &&
38
+ config.maxDecompressedSize <= 0) {
39
+ throw new Errors_1.ConfigurationError("maxDecompressedSize must be positive");
40
+ }
41
+ }
42
+ /**
43
+ * Converts a CompressionConfiguration to the protobuf format.
44
+ * @internal
45
+ */
46
+ function compressionConfigToProtobuf(config,
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ connection_request) {
49
+ validateCompressionConfiguration(config);
50
+ const proto = {
51
+ enabled: config.enabled,
52
+ backend: config.backend ?? CompressionBackend.ZSTD,
53
+ minCompressionSize: config.minCompressionSize ?? DEFAULT_MIN_COMPRESSION_SIZE,
54
+ };
55
+ if (config.compressionLevel !== undefined) {
56
+ proto.compressionLevel = config.compressionLevel;
57
+ }
58
+ // Handle maxDecompressedSize:
59
+ // - undefined = don't set field, let Rust use its default (512MB)
60
+ // - number > 0 = use that value
61
+ if (config.maxDecompressedSize !== undefined) {
62
+ proto.maxDecompressedSize = config.maxDecompressedSize;
63
+ }
64
+ return connection_request.CompressionConfig.create(proto);
65
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
+ */
4
+ /**
5
+ * Enum representing cache eviction policies.
6
+ *
7
+ * Eviction policies determine which entries are removed from the cache
8
+ * when the cache reaches its maximum memory limit.
9
+ */
10
+ export declare enum EvictionPolicy {
11
+ /**
12
+ * Least Recently Used eviction policy.
13
+ * Removes the entries that have been accessed least recently.
14
+ */
15
+ LRU = 0,
16
+ /**
17
+ * Least Frequently Used eviction policy.
18
+ * Removes the entries that have been accessed least frequently.
19
+ */
20
+ LFU = 1
21
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EvictionPolicy = void 0;
7
+ /**
8
+ * Enum representing cache eviction policies.
9
+ *
10
+ * Eviction policies determine which entries are removed from the cache
11
+ * when the cache reaches its maximum memory limit.
12
+ */
13
+ var EvictionPolicy;
14
+ (function (EvictionPolicy) {
15
+ /**
16
+ * Least Recently Used eviction policy.
17
+ * Removes the entries that have been accessed least recently.
18
+ */
19
+ EvictionPolicy[EvictionPolicy["LRU"] = 0] = "LRU";
20
+ /**
21
+ * Least Frequently Used eviction policy.
22
+ * Removes the entries that have been accessed least frequently.
23
+ */
24
+ EvictionPolicy[EvictionPolicy["LFU"] = 1] = "LFU";
25
+ })(EvictionPolicy || (exports.EvictionPolicy = EvictionPolicy = {}));
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
3
  */
4
- import { AdvancedBaseClientConfiguration, BaseClient, BaseClientConfiguration, DecoderOption, GlideReturnType, GlideString, PubSubMsg } from "./BaseClient";
4
+ import { AdvancedBaseClientConfiguration, BaseClient, BaseClientConfiguration, DecoderOption, GlideReturnType, GlideString, PubSubMsg, NodeDiscoveryMode } from "./BaseClient";
5
5
  import { Batch } from "./Batch";
6
6
  import { BatchOptions, FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsFullResponse, InfoOptions, LolwutOptions, ScanOptions } from "./Commands";
7
7
  export declare namespace GlideClientConfiguration {
@@ -75,12 +75,14 @@ export interface StandalonePubSubState {
75
75
  * This configuration allows you to tailor the client's behavior when connecting to a standalone Valkey Glide server.
76
76
  *
77
77
  * - **Database Selection**: Use `databaseId` (inherited from BaseClientConfiguration) to specify which logical database to connect to.
78
+ * - **Client-Side Caching**: Use `clientSideCache` (inherited from BaseClientConfiguration) to enable local caching for improved performance.
78
79
  * - **Pub/Sub Subscriptions**: Predefine Pub/Sub channels and patterns to subscribe to upon connection establishment.
79
80
  *
80
81
  * @example
81
82
  * ```typescript
82
83
  * const config: GlideClientConfiguration = {
83
84
  * databaseId: 1, // Inherited from BaseClientConfiguration
85
+ * clientSideCache: ClientSideCache.create(1024, 60000), // 1MB cache, 1 min TTL
84
86
  * pubsubSubscriptions: {
85
87
  * channelsAndPatterns: {
86
88
  * [GlideClientConfiguration.PubSubChannelModes.Pattern]: new Set(['news.*']),
@@ -120,6 +122,12 @@ export type GlideClientConfiguration = BaseClientConfiguration & {
120
122
  * Defaults to false.
121
123
  */
122
124
  readOnly?: boolean;
125
+ /**
126
+ * Controls how the client discovers node roles and topology in standalone mode.
127
+ *
128
+ * @see {@link NodeDiscoveryMode} for available modes.
129
+ */
130
+ nodeDiscoveryMode?: NodeDiscoveryMode;
123
131
  };
124
132
  /**
125
133
  * Represents advanced configuration settings for creating a {@link GlideClient | GlideClient} used in {@link GlideClientConfiguration | GlideClientConfiguration}.
@@ -45,6 +45,10 @@ class GlideClient extends BaseClient_1.BaseClient {
45
45
  if (options.readOnly !== undefined) {
46
46
  configuration.readOnly = options.readOnly;
47
47
  }
48
+ if (options.nodeDiscoveryMode !== undefined) {
49
+ configuration.nodeDiscoveryMode =
50
+ options.nodeDiscoveryMode;
51
+ }
48
52
  return configuration;
49
53
  }
50
54
  /**
@@ -130,6 +130,7 @@ export interface ClusterPubSubState {
130
130
  * - `"enabledDefaultConfigs"`: Enables periodic checks with default configurations.
131
131
  * - `"disabled"`: Disables periodic topology checks.
132
132
  * - `{ duration_in_sec: number }`: Manually configure the interval for periodic checks.
133
+ * - **Client-Side Caching**: Use `clientSideCache` (inherited from BaseClientConfiguration) to enable local caching for improved performance.
133
134
  * - **Pub/Sub Subscriptions**: Predefine Pub/Sub channels and patterns to subscribe to upon connection establishment.
134
135
  * - Supports exact channels, patterns, and sharded channels (available since Valkey version 7.0).
135
136
  *
@@ -141,6 +142,7 @@ export interface ClusterPubSubState {
141
142
  * { host: 'cluster-node-2.example.com', port: 6379 },
142
143
  * ],
143
144
  * databaseId: 5, // Connect to database 5 (requires Valkey 9.0+ with multi-database cluster mode)
145
+ * clientSideCache: ClientSideCache.create(2048, 0), // Enable 2MB client-side cache, no TTL
144
146
  * periodicChecks: {
145
147
  * duration_in_sec: 30, // Perform periodic checks every 30 seconds
146
148
  * },
@@ -1378,6 +1378,85 @@ export namespace command_request {
1378
1378
  public static getTypeUrl(typeUrlPrefix?: string): string;
1379
1379
  }
1380
1380
 
1381
+ /** Properties of a GetCacheMetrics. */
1382
+ interface IGetCacheMetrics {
1383
+
1384
+ /** GetCacheMetrics metricsTypes */
1385
+ metricsTypes?: (command_request.CacheMetricsType|null);
1386
+ }
1387
+
1388
+ /** Represents a GetCacheMetrics. */
1389
+ class GetCacheMetrics implements IGetCacheMetrics {
1390
+
1391
+ /**
1392
+ * Constructs a new GetCacheMetrics.
1393
+ * @param [properties] Properties to set
1394
+ */
1395
+ constructor(properties?: command_request.IGetCacheMetrics);
1396
+
1397
+ /** GetCacheMetrics metricsTypes. */
1398
+ public metricsTypes: command_request.CacheMetricsType;
1399
+
1400
+ /**
1401
+ * Creates a new GetCacheMetrics instance using the specified properties.
1402
+ * @param [properties] Properties to set
1403
+ * @returns GetCacheMetrics instance
1404
+ */
1405
+ public static create(properties?: command_request.IGetCacheMetrics): command_request.GetCacheMetrics;
1406
+
1407
+ /**
1408
+ * Encodes the specified GetCacheMetrics message. Does not implicitly {@link command_request.GetCacheMetrics.verify|verify} messages.
1409
+ * @param message GetCacheMetrics message or plain object to encode
1410
+ * @param [writer] Writer to encode to
1411
+ * @returns Writer
1412
+ */
1413
+ public static encode(message: command_request.IGetCacheMetrics, writer?: $protobuf.Writer): $protobuf.Writer;
1414
+
1415
+ /**
1416
+ * Encodes the specified GetCacheMetrics message, length delimited. Does not implicitly {@link command_request.GetCacheMetrics.verify|verify} messages.
1417
+ * @param message GetCacheMetrics message or plain object to encode
1418
+ * @param [writer] Writer to encode to
1419
+ * @returns Writer
1420
+ */
1421
+ public static encodeDelimited(message: command_request.IGetCacheMetrics, writer?: $protobuf.Writer): $protobuf.Writer;
1422
+
1423
+ /**
1424
+ * Decodes a GetCacheMetrics message from the specified reader or buffer.
1425
+ * @param reader Reader or buffer to decode from
1426
+ * @param [length] Message length if known beforehand
1427
+ * @returns GetCacheMetrics
1428
+ * @throws {Error} If the payload is not a reader or valid buffer
1429
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1430
+ */
1431
+ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): command_request.GetCacheMetrics;
1432
+
1433
+ /**
1434
+ * Decodes a GetCacheMetrics message from the specified reader or buffer, length delimited.
1435
+ * @param reader Reader or buffer to decode from
1436
+ * @returns GetCacheMetrics
1437
+ * @throws {Error} If the payload is not a reader or valid buffer
1438
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1439
+ */
1440
+ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): command_request.GetCacheMetrics;
1441
+
1442
+ /**
1443
+ * Gets the default type url for GetCacheMetrics
1444
+ * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1445
+ * @returns The default type url
1446
+ */
1447
+ public static getTypeUrl(typeUrlPrefix?: string): string;
1448
+ }
1449
+
1450
+ /** CacheMetricsType enum. */
1451
+ enum CacheMetricsType {
1452
+ HitRate = 0,
1453
+ MissRate = 1,
1454
+ EntryCount = 2,
1455
+ Evictions = 3,
1456
+ Expirations = 4,
1457
+ TotalLookups = 5
1458
+ }
1459
+
1381
1460
  /** Properties of a CommandRequest. */
1382
1461
  interface ICommandRequest {
1383
1462
 
@@ -1405,6 +1484,9 @@ export namespace command_request {
1405
1484
  /** CommandRequest refreshIamToken */
1406
1485
  refreshIamToken?: (command_request.IRefreshIamToken|null);
1407
1486
 
1487
+ /** CommandRequest getCacheMetrics */
1488
+ getCacheMetrics?: (command_request.IGetCacheMetrics|null);
1489
+
1408
1490
  /** CommandRequest route */
1409
1491
  route?: (command_request.IRoutes|null);
1410
1492
 
@@ -1445,6 +1527,9 @@ export namespace command_request {
1445
1527
  /** CommandRequest refreshIamToken. */
1446
1528
  public refreshIamToken?: (command_request.IRefreshIamToken|null);
1447
1529
 
1530
+ /** CommandRequest getCacheMetrics. */
1531
+ public getCacheMetrics?: (command_request.IGetCacheMetrics|null);
1532
+
1448
1533
  /** CommandRequest route. */
1449
1534
  public route?: (command_request.IRoutes|null);
1450
1535
 
@@ -1452,7 +1537,7 @@ export namespace command_request {
1452
1537
  public rootSpanPtr?: (number|Long|null);
1453
1538
 
1454
1539
  /** CommandRequest command. */
1455
- public command?: ("singleCommand"|"batch"|"scriptInvocation"|"scriptInvocationPointers"|"clusterScan"|"updateConnectionPassword"|"refreshIamToken");
1540
+ public command?: ("singleCommand"|"batch"|"scriptInvocation"|"scriptInvocationPointers"|"clusterScan"|"updateConnectionPassword"|"refreshIamToken"|"getCacheMetrics");
1456
1541
 
1457
1542
  /**
1458
1543
  * Creates a new CommandRequest instance using the specified properties.
@@ -1589,7 +1674,8 @@ export namespace connection_request {
1589
1674
  PreferReplica = 1,
1590
1675
  LowestLatency = 2,
1591
1676
  AZAffinity = 3,
1592
- AZAffinityReplicasAndPrimary = 4
1677
+ AZAffinityReplicasAndPrimary = 4,
1678
+ AllNodes = 5
1593
1679
  }
1594
1680
 
1595
1681
  /** TlsMode enum. */
@@ -1924,6 +2010,13 @@ export namespace connection_request {
1924
2010
  LZ4 = 1
1925
2011
  }
1926
2012
 
2013
+ /** NodeDiscoveryMode enum. */
2014
+ enum NodeDiscoveryMode {
2015
+ Standard = 0,
2016
+ Static = 1,
2017
+ DiscoverAll = 2
2018
+ }
2019
+
1927
2020
  /** Properties of a CompressionConfig. */
1928
2021
  interface ICompressionConfig {
1929
2022
 
@@ -1938,6 +2031,9 @@ export namespace connection_request {
1938
2031
 
1939
2032
  /** CompressionConfig minCompressionSize */
1940
2033
  minCompressionSize?: (number|null);
2034
+
2035
+ /** CompressionConfig maxDecompressedSize */
2036
+ maxDecompressedSize?: (number|Long|null);
1941
2037
  }
1942
2038
 
1943
2039
  /** Represents a CompressionConfig. */
@@ -1961,6 +2057,9 @@ export namespace connection_request {
1961
2057
  /** CompressionConfig minCompressionSize. */
1962
2058
  public minCompressionSize: number;
1963
2059
 
2060
+ /** CompressionConfig maxDecompressedSize. */
2061
+ public maxDecompressedSize?: (number|Long|null);
2062
+
1964
2063
  /**
1965
2064
  * Creates a new CompressionConfig instance using the specified properties.
1966
2065
  * @param [properties] Properties to set
@@ -2149,6 +2248,105 @@ export namespace connection_request {
2149
2248
  public static getTypeUrl(typeUrlPrefix?: string): string;
2150
2249
  }
2151
2250
 
2251
+ /** Properties of a ClientSideCache. */
2252
+ interface IClientSideCache {
2253
+
2254
+ /** ClientSideCache cacheId */
2255
+ cacheId?: (string|null);
2256
+
2257
+ /** ClientSideCache maxCacheKb */
2258
+ maxCacheKb?: (number|Long|null);
2259
+
2260
+ /** ClientSideCache entryTtlMs */
2261
+ entryTtlMs?: (number|Long|null);
2262
+
2263
+ /** ClientSideCache evictionPolicy */
2264
+ evictionPolicy?: (connection_request.EvictionPolicy|null);
2265
+
2266
+ /** ClientSideCache enableMetrics */
2267
+ enableMetrics?: (boolean|null);
2268
+ }
2269
+
2270
+ /** Represents a ClientSideCache. */
2271
+ class ClientSideCache implements IClientSideCache {
2272
+
2273
+ /**
2274
+ * Constructs a new ClientSideCache.
2275
+ * @param [properties] Properties to set
2276
+ */
2277
+ constructor(properties?: connection_request.IClientSideCache);
2278
+
2279
+ /** ClientSideCache cacheId. */
2280
+ public cacheId: string;
2281
+
2282
+ /** ClientSideCache maxCacheKb. */
2283
+ public maxCacheKb: (number|Long);
2284
+
2285
+ /** ClientSideCache entryTtlMs. */
2286
+ public entryTtlMs: (number|Long);
2287
+
2288
+ /** ClientSideCache evictionPolicy. */
2289
+ public evictionPolicy?: (connection_request.EvictionPolicy|null);
2290
+
2291
+ /** ClientSideCache enableMetrics. */
2292
+ public enableMetrics: boolean;
2293
+
2294
+ /**
2295
+ * Creates a new ClientSideCache instance using the specified properties.
2296
+ * @param [properties] Properties to set
2297
+ * @returns ClientSideCache instance
2298
+ */
2299
+ public static create(properties?: connection_request.IClientSideCache): connection_request.ClientSideCache;
2300
+
2301
+ /**
2302
+ * Encodes the specified ClientSideCache message. Does not implicitly {@link connection_request.ClientSideCache.verify|verify} messages.
2303
+ * @param message ClientSideCache message or plain object to encode
2304
+ * @param [writer] Writer to encode to
2305
+ * @returns Writer
2306
+ */
2307
+ public static encode(message: connection_request.IClientSideCache, writer?: $protobuf.Writer): $protobuf.Writer;
2308
+
2309
+ /**
2310
+ * Encodes the specified ClientSideCache message, length delimited. Does not implicitly {@link connection_request.ClientSideCache.verify|verify} messages.
2311
+ * @param message ClientSideCache message or plain object to encode
2312
+ * @param [writer] Writer to encode to
2313
+ * @returns Writer
2314
+ */
2315
+ public static encodeDelimited(message: connection_request.IClientSideCache, writer?: $protobuf.Writer): $protobuf.Writer;
2316
+
2317
+ /**
2318
+ * Decodes a ClientSideCache message from the specified reader or buffer.
2319
+ * @param reader Reader or buffer to decode from
2320
+ * @param [length] Message length if known beforehand
2321
+ * @returns ClientSideCache
2322
+ * @throws {Error} If the payload is not a reader or valid buffer
2323
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
2324
+ */
2325
+ public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): connection_request.ClientSideCache;
2326
+
2327
+ /**
2328
+ * Decodes a ClientSideCache message from the specified reader or buffer, length delimited.
2329
+ * @param reader Reader or buffer to decode from
2330
+ * @returns ClientSideCache
2331
+ * @throws {Error} If the payload is not a reader or valid buffer
2332
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
2333
+ */
2334
+ public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): connection_request.ClientSideCache;
2335
+
2336
+ /**
2337
+ * Gets the default type url for ClientSideCache
2338
+ * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
2339
+ * @returns The default type url
2340
+ */
2341
+ public static getTypeUrl(typeUrlPrefix?: string): string;
2342
+ }
2343
+
2344
+ /** EvictionPolicy enum. */
2345
+ enum EvictionPolicy {
2346
+ LRU = 0,
2347
+ LFU = 1
2348
+ }
2349
+
2152
2350
  /** Properties of a ConnectionRequest. */
2153
2351
  interface IConnectionRequest {
2154
2352
 
@@ -2229,6 +2427,12 @@ export namespace connection_request {
2229
2427
 
2230
2428
  /** ConnectionRequest readOnly */
2231
2429
  readOnly?: (boolean|null);
2430
+
2431
+ /** ConnectionRequest clientSideCache */
2432
+ clientSideCache?: (connection_request.IClientSideCache|null);
2433
+
2434
+ /** ConnectionRequest nodeDiscoveryMode */
2435
+ nodeDiscoveryMode?: (connection_request.NodeDiscoveryMode|null);
2232
2436
  }
2233
2437
 
2234
2438
  /** Represents a ConnectionRequest. */
@@ -2318,6 +2522,12 @@ export namespace connection_request {
2318
2522
  /** ConnectionRequest readOnly. */
2319
2523
  public readOnly?: (boolean|null);
2320
2524
 
2525
+ /** ConnectionRequest clientSideCache. */
2526
+ public clientSideCache?: (connection_request.IClientSideCache|null);
2527
+
2528
+ /** ConnectionRequest nodeDiscoveryMode. */
2529
+ public nodeDiscoveryMode: connection_request.NodeDiscoveryMode;
2530
+
2321
2531
  /** ConnectionRequest periodicChecks. */
2322
2532
  public periodicChecks?: ("periodicChecksManualInterval"|"periodicChecksDisabled");
2323
2533