You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Client Side Caching (#2947)
* CSC POC ontop of Parser * add csc file that weren't merged after patch * address review comments * nits to try and fix github * last change from review * Update client-side cache and improve documentation * Add client side caching RESP3 validation * Add documentation for RESP and unstableResp3 options * Add comprehensive cache statistics The `CacheStats` class provides detailed metrics like hit/miss counts, load success/failure counts, total load time, and eviction counts. It also offers derived metrics such as hit/miss rates, load failure rate, and average load penalty. The design is inspired by Caffeine. `BasicClientSideCache` now uses a `StatsCounter` to accumulate these statistics, exposed via a new `stats()` method. The previous `cacheHits()` and `cacheMisses()` methods have been removed. A `recordStats` option (default: true) in `ClientSideCacheConfig` allows disabling statistics collection. --------- Co-authored-by: Shaya Potter <shaya@redislabs.com>
This commit is contained in:
48
packages/client/lib/cluster/cluster-slots.spec.ts
Normal file
48
packages/client/lib/cluster/cluster-slots.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { RedisClusterOptions, RedisClusterClientOptions } from './index';
|
||||
import RedisClusterSlots from './cluster-slots';
|
||||
|
||||
describe('RedisClusterSlots', () => {
|
||||
describe('initialization', () => {
|
||||
|
||||
describe('clientSideCache validation', () => {
|
||||
const mockEmit = ((_event: string | symbol, ..._args: any[]): boolean => true) as EventEmitter['emit'];
|
||||
const clientSideCacheConfig = { ttl: 0, maxEntries: 0 };
|
||||
const rootNodes: Array<RedisClusterClientOptions> = [
|
||||
{ socket: { host: 'localhost', port: 30001 } }
|
||||
];
|
||||
|
||||
it('should throw error when clientSideCache is enabled with RESP 2', () => {
|
||||
assert.throws(
|
||||
() => new RedisClusterSlots({
|
||||
rootNodes,
|
||||
clientSideCache: clientSideCacheConfig,
|
||||
RESP: 2 as const,
|
||||
}, mockEmit),
|
||||
new Error('Client Side Caching is only supported with RESP3')
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw error when clientSideCache is enabled with RESP undefined', () => {
|
||||
assert.throws(
|
||||
() => new RedisClusterSlots({
|
||||
rootNodes,
|
||||
clientSideCache: clientSideCacheConfig,
|
||||
}, mockEmit),
|
||||
new Error('Client Side Caching is only supported with RESP3')
|
||||
);
|
||||
});
|
||||
|
||||
it('should not throw when clientSideCache is enabled with RESP 3', () => {
|
||||
assert.doesNotThrow(() =>
|
||||
new RedisClusterSlots({
|
||||
rootNodes,
|
||||
clientSideCache: clientSideCacheConfig,
|
||||
RESP: 3 as const,
|
||||
}, mockEmit)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user