Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import { RedisVariadicArgument, parseArgs, pushVariadicArguments } from '../comm
import { BasicClientSideCache, ClientSideCacheConfig, ClientSideCacheProvider } from './cache';
import { BasicCommandParser, CommandParser } from './parser';
import SingleEntryCache from '../single-entry-cache';
import { version } from '../../package.json'
import EnterpriseMaintenanceManager, { MaintenanceUpdate, MovingEndpointType } from './enterprise-maintenance-manager';
import { resolve } from 'node:path';
import { readFile } from 'node:fs/promises';

export interface RedisClientOptions<
M extends RedisModules = RedisModules,
Expand Down Expand Up @@ -741,7 +742,7 @@ export default class RedisClient<

if (!this.#options.disableClientInfo) {
commands.push({
cmd: ['CLIENT', 'SETINFO', 'LIB-VER', version],
cmd: ['CLIENT', 'SETINFO', 'LIB-VER', await getPackageVersion()],
errorHandler: () => {
// Client libraries are expected to pipeline this command
// after authentication on all connections and ignore failures
Expand All @@ -765,17 +766,17 @@ export default class RedisClient<
}
});
}

if (this.#clientSideCache) {
commands.push({cmd: this.#clientSideCache.trackingOn()});
}

if (this.#options?.emitInvalidate) {
commands.push({cmd: ['CLIENT', 'TRACKING', 'ON']});
}

const maintenanceHandshakeCmd = await EnterpriseMaintenanceManager.getHandshakeCommand(this.#options);

if(maintenanceHandshakeCmd) {
commands.push(maintenanceHandshakeCmd);
};
Expand Down Expand Up @@ -1559,4 +1560,22 @@ export default class RedisClient<
unref() {
this._self.#socket.unref();
}

}

let cachedVersion = "error-fetching-version";
async function getPackageVersion() {
if (cachedVersion) {
return cachedVersion;
}
try {
const filePath = resolve(__dirname, "..", "..", "package.json");
const data = await readFile(filePath, "utf8");
const parsed = JSON.parse(data);
cachedVersion = parsed.version;
return cachedVersion;
} catch (err) {
cachedVersion = "error-fetching-version";
return cachedVersion;
}
}
8 changes: 7 additions & 1 deletion packages/client/lib/commands/CLIENT_INFO.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import { strict as assert } from 'node:assert';
import CLIENT_INFO from './CLIENT_INFO';
import testUtils, { GLOBAL } from '../test-utils';
import { parseArgs } from './generic-transformers';
import { version } from '../../package.json';
import { resolve } from 'node:path';
import { readFileSync } from 'node:fs';

describe('CLIENT INFO', () => {

const filePath = resolve(__dirname, "..", "..", "package.json");
const data = readFileSync(filePath, "utf8");
const version = JSON.parse(data).version;

testUtils.isVersionGreaterThanHook([6, 2]);

it('transformArguments', () => {
Expand Down
Loading