Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note that cluster_client.ping() no longer exists #2743

Open
wants to merge 2 commits into
base: v5
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/v4-to-v5.md
Expand Up @@ -106,6 +106,10 @@ await pool.ping();

See the [pool guide](./pool.md) for more information.

## Cluster 'PING'

in v4, `cluster.ping()` would send the ping command to a random node, in v5, this command is no longer available to the cluster client

## Cluster `MULTI`

In v4, `cluster.multi()` did not support executing commands on replicas, even if they were readonly.
Expand Down
40 changes: 40 additions & 0 deletions packages/client/lib/commands/HEXPIRE.spec.ts
@@ -0,0 +1,40 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HEXPIRE from './HEXPIRE';

describe('HEXPIRE', () => {
testUtils.isVersionGreaterThanHook([7, 4]);

describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
HEXPIRE.transformArguments('key', 'field', 1),
['HEXPIRE', 'key', '1', '1', 'field']
);
});

it('array', () => {
assert.deepEqual(
HEXPIRE.transformArguments('key', ['field1', 'field2'], 1),
['HEXPIRE', 'key', '1', '2', 'field1', 'field2']
);
});

it('with set option', () => {
assert.deepEqual(
HEXPIRE.transformArguments('key', 'field1', 1, 'NX'),
['HEXPIRE', 'key', '1', 'NX', '1', 'field1']
);
});
});

testUtils.testAll('hexpire', async client => {
assert.equal(
await client.hExpire('key', ['field1'], 0),
null,
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
42 changes: 42 additions & 0 deletions packages/client/lib/commands/HEXPIRE.ts
@@ -0,0 +1,42 @@
import { Command, NullReply, RedisArgument } from "../RESP/types";
import { RedisVariadicArgument, pushVariadicArgument } from "./generic-transformers";

/**
* @readonly
* @enum {number}
*/
export const HASH_EXPIRATION = {
/** @property {number} */
/** The field does not exist */
FieldNotExists: -2,
/** @property {number} */
/** Specified NX | XX | GT | LT condition not met */
ConditionNotMet: 0,
/** @property {number} */
/** Expiration time was set or updated */
Updated: 1,
/** @property {number} */
/** Field deleted because the specified expiration time is in the past */
Deleted: 2
} as const;

export type HashExpiration = typeof HASH_EXPIRATION[keyof typeof HASH_EXPIRATION];

export default {
FIRST_KEY_INDEX: 1,
transformArguments(
key: RedisArgument,
fields: RedisVariadicArgument,
seconds: number,
mode?: 'NX' | 'XX' | 'GT' | 'LT',
) {
const args = ['HEXPIRE', key, seconds.toString()];

if (mode) {
args.push(mode);
}

return pushVariadicArgument(args, fields);
},
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration>
} as const satisfies Command;
48 changes: 48 additions & 0 deletions packages/client/lib/commands/HEXPIREAT.spec.ts
@@ -0,0 +1,48 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HEXPIREAT from './HEXPIREAT';

describe('HEXPIREAT', () => {
testUtils.isVersionGreaterThanHook([7, 4]);

describe('transformArguments', () => {
it('string + number', () => {
assert.deepEqual(
HEXPIREAT.transformArguments('key', 'field', 1),
['HEXPIREAT', 'key', '1', '1', 'field']
);
});

it('array + number', () => {
assert.deepEqual(
HEXPIREAT.transformArguments('key', ['field1', 'field2'], 1),
['HEXPIREAT', 'key', '1', '2', 'field1', 'field2']
);
});

it('date', () => {
const d = new Date();
assert.deepEqual(
HEXPIREAT.transformArguments('key', ['field1'], d),
['HEXPIREAT', 'key', Math.floor(d.getTime() / 1000).toString(), '1', 'field1']
);
});

it('with set option', () => {
assert.deepEqual(
HEXPIREAT.transformArguments('key', 'field1', 1, 'GT'),
['HEXPIREAT', 'key', '1', 'GT', 1, 'field1']
);
});
});

testUtils.testAll('expireAt', async client => {
assert.equal(
await client.hExpireAt('key', 'field1', 1),
null
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
23 changes: 23 additions & 0 deletions packages/client/lib/commands/HEXPIREAT.ts
@@ -0,0 +1,23 @@
import { RedisArgument, Command, NullReply } from '../RESP/types';
import { HashExpiration } from './HEXPIRE';
import { RedisVariadicArgument, pushVariadicArgument, transformEXAT } from './generic-transformers';

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(
key: RedisArgument,
fields: RedisVariadicArgument,
timestamp: number | Date,
mode?: 'NX' | 'XX' | 'GT' | 'LT'
) {
const args = ['HEXPIREAT', key, transformEXAT(timestamp)];

if (mode) {
args.push(mode);
}

return pushVariadicArgument(args, fields);
},
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration>
} as const satisfies Command;
33 changes: 33 additions & 0 deletions packages/client/lib/commands/HEXPIRETIME.spec.ts
@@ -0,0 +1,33 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HEXPIRETIME from './HEXPIRETIME';

describe('HEXPIRETIME', () => {
testUtils.isVersionGreaterThanHook([7, 4]);

describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
HEXPIRETIME.transformArguments('key', 'field'),
['HEXPIRETIME', 'key', '1', 'field']
);
});

it('array', () => {
assert.deepEqual(
HEXPIRETIME.transformArguments('key', ['field1', 'field2']),
['HEXPIRETIME', 'key', '2', 'field1', 'field2']
);
});
})

testUtils.testAll('hExpireTime', async client => {
assert.equal(
await client.hExpireTime('key', 'field1'),
null
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
20 changes: 20 additions & 0 deletions packages/client/lib/commands/HEXPIRETIME.ts
@@ -0,0 +1,20 @@
import { RedisArgument, NumberReply, Command, NullReply, ArrayReply } from '../RESP/types';
import { RedisVariadicArgument, pushVariadicArgument } from './generic-transformers';

export const HASH_EXPIRATION_TIME = {
/** @property {number} */
/** The field does not exist */
FieldNotExists: -2,
/** @property {number} */
/** The field exists but has no associated expire */
NoExpiration: -1,
} as const;

export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument, fields: RedisVariadicArgument) {
return pushVariadicArgument(['HEXPIRETIME', key], fields);
},
transformReply: undefined as unknown as () => NullReply | ArrayReply<NumberReply>
} as const satisfies Command;
33 changes: 33 additions & 0 deletions packages/client/lib/commands/HPERSIST.spec.ts
@@ -0,0 +1,33 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HPERSIST from './HPERSIST';

describe('PERSIST', () => {
testUtils.isVersionGreaterThanHook([7, 4]);

describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
HPERSIST.transformArguments('key', 'field'),
['PERSIST', 'key', '1', 'field']
);
});

it('array', () => {
assert.deepEqual(
HPERSIST.transformArguments('key', ['field1', 'field2']),
['PERSIST', 'key', '2', 'field1', 'field2']
);
});
})

testUtils.testAll('hPersist', async client => {
assert.equal(
await client.hPersist('key', 'field1'),
null
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
10 changes: 10 additions & 0 deletions packages/client/lib/commands/HPERSIST.ts
@@ -0,0 +1,10 @@
import { RedisArgument, NumberReply, Command, NullReply, ArrayReply } from '../RESP/types';
import { RedisVariadicArgument, pushVariadicArgument } from './generic-transformers';

export default {
FIRST_KEY_INDEX: 1,
transformArguments(key: RedisArgument, fields: RedisVariadicArgument) {
return pushVariadicArgument(['PERSIST', key], fields);
},
transformReply: undefined as unknown as () => NullReply | ArrayReply<NumberReply>
} as const satisfies Command;
40 changes: 40 additions & 0 deletions packages/client/lib/commands/HPEXPIRE.spec.ts
@@ -0,0 +1,40 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HPEXPIRE from './HPEXPIRE';

describe('HEXPIRE', () => {
testUtils.isVersionGreaterThanHook([7, 4]);

describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
HPEXPIRE.transformArguments('key', 'field', 1),
['HPEXPIRE', 'key', '1', '1', 'field']
);
});

it('array', () => {
assert.deepEqual(
HPEXPIRE.transformArguments('key', ['field1', 'field2'], 1),
['HPEXPIRE', 'key', '1', '2', 'field1', 'field2']
);
});

it('with set option', () => {
assert.deepEqual(
HPEXPIRE.transformArguments('key', ['field1'], 1, 'NX'),
['HPEXPIRE', 'key', '1', 'NX', '1', 'field1']
);
});
});

testUtils.testAll('hexpire', async client => {
assert.equal(
await client.hpExpire('key', ['field1'], 0),
null,
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
22 changes: 22 additions & 0 deletions packages/client/lib/commands/HPEXPIRE.ts
@@ -0,0 +1,22 @@
import { Command, NullReply, RedisArgument } from "../RESP/types";
import { HashExpiration } from "./HEXPIRE";
import { RedisVariadicArgument, pushVariadicArgument } from "./generic-transformers";

export default {
FIRST_KEY_INDEX: 1,
transformArguments(
key: RedisArgument,
fields: RedisVariadicArgument,
ms: number,
mode?: 'NX' | 'XX' | 'GT' | 'LT',
) {
const args = ['HPEXPIRE', key, ms.toString()];

if (mode) {
args.push(mode);
}

return pushVariadicArgument(args, fields);
},
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration>
} as const satisfies Command;
48 changes: 48 additions & 0 deletions packages/client/lib/commands/HPEXPIREAT.spec.ts
@@ -0,0 +1,48 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import HPEXPIREAT from './HPEXPIREAT';

describe('HPEXPIREAT', () => {
testUtils.isVersionGreaterThanHook([7, 4]);

describe('transformArguments', () => {
it('string + number', () => {
assert.deepEqual(
HPEXPIREAT.transformArguments('key', 'field', 1),
['HPEXPIREAT', 'key', '1', '1', 'field']
);
});

it('array + number', () => {
assert.deepEqual(
HPEXPIREAT.transformArguments('key', ['field1', 'field2'], 1),
['HPEXPIREAT', 'key', '1', '2', 'field1', 'field2']
);
});

it('date', () => {
const d = new Date();
assert.deepEqual(
HPEXPIREAT.transformArguments('key', ['field1'], d),
['HPEXPIREAT', 'key', d.getTime().toString(), '1', 'field1']
);
});

it('with set option', () => {
assert.deepEqual(
HPEXPIREAT.transformArguments('key', ['field1'], 1, 'XX'),
['HPEXPIREAT', 'key', '1', 'XX', '1', 'field1']
);
});
});

testUtils.testAll('hpExpireAt', async client => {
assert.equal(
await client.hpExpireAt('key', ['field1'], 1),
null,
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});