You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-04 15:02:09 +03:00
Support new expire features (#2036)
* Support new expire features * Update PEXPIRETIME.ts * Update EXPIRETIME.ts * fix version skip * clean code Co-authored-by: leibale <leibale1998@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import * as EVALSHA from '../commands/EVALSHA';
|
|||||||
import * as EXISTS from '../commands/EXISTS';
|
import * as EXISTS from '../commands/EXISTS';
|
||||||
import * as EXPIRE from '../commands/EXPIRE';
|
import * as EXPIRE from '../commands/EXPIRE';
|
||||||
import * as EXPIREAT from '../commands/EXPIREAT';
|
import * as EXPIREAT from '../commands/EXPIREAT';
|
||||||
|
import * as EXPIRETIME from '../commands/EXPIRETIME';
|
||||||
import * as GEOADD from '../commands/GEOADD';
|
import * as GEOADD from '../commands/GEOADD';
|
||||||
import * as GEODIST from '../commands/GEODIST';
|
import * as GEODIST from '../commands/GEODIST';
|
||||||
import * as GEOHASH from '../commands/GEOHASH';
|
import * as GEOHASH from '../commands/GEOHASH';
|
||||||
@@ -75,6 +76,7 @@ import * as MSETNX from '../commands/MSETNX';
|
|||||||
import * as PERSIST from '../commands/PERSIST';
|
import * as PERSIST from '../commands/PERSIST';
|
||||||
import * as PEXPIRE from '../commands/PEXPIRE';
|
import * as PEXPIRE from '../commands/PEXPIRE';
|
||||||
import * as PEXPIREAT from '../commands/PEXPIREAT';
|
import * as PEXPIREAT from '../commands/PEXPIREAT';
|
||||||
|
import * as PEXPIRETIME from '../commands/PEXPIRETIME';
|
||||||
import * as PFADD from '../commands/PFADD';
|
import * as PFADD from '../commands/PFADD';
|
||||||
import * as PFCOUNT from '../commands/PFCOUNT';
|
import * as PFCOUNT from '../commands/PFCOUNT';
|
||||||
import * as PFMERGE from '../commands/PFMERGE';
|
import * as PFMERGE from '../commands/PFMERGE';
|
||||||
@@ -224,6 +226,8 @@ export default {
|
|||||||
expire: EXPIRE,
|
expire: EXPIRE,
|
||||||
EXPIREAT,
|
EXPIREAT,
|
||||||
expireAt: EXPIREAT,
|
expireAt: EXPIREAT,
|
||||||
|
EXPIRETIME,
|
||||||
|
expireTime: EXPIRETIME,
|
||||||
GEOADD,
|
GEOADD,
|
||||||
geoAdd: GEOADD,
|
geoAdd: GEOADD,
|
||||||
GEODIST,
|
GEODIST,
|
||||||
@@ -332,6 +336,8 @@ export default {
|
|||||||
pExpire: PEXPIRE,
|
pExpire: PEXPIRE,
|
||||||
PEXPIREAT,
|
PEXPIREAT,
|
||||||
pExpireAt: PEXPIREAT,
|
pExpireAt: PEXPIREAT,
|
||||||
|
PEXPIRETIME,
|
||||||
|
pExpireTime: PEXPIRETIME,
|
||||||
PFADD,
|
PFADD,
|
||||||
pfAdd: PFADD,
|
pfAdd: PFADD,
|
||||||
PFCOUNT,
|
PFCOUNT,
|
||||||
|
@@ -3,11 +3,20 @@ import testUtils, { GLOBAL } from '../test-utils';
|
|||||||
import { transformArguments } from './EXPIRE';
|
import { transformArguments } from './EXPIRE';
|
||||||
|
|
||||||
describe('EXPIRE', () => {
|
describe('EXPIRE', () => {
|
||||||
it('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
assert.deepEqual(
|
it('simple', () => {
|
||||||
transformArguments('key', 1),
|
assert.deepEqual(
|
||||||
['EXPIRE', 'key', '1']
|
transformArguments('key', 1),
|
||||||
);
|
['EXPIRE', 'key', '1']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with set option', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('key', 1, 'NX'),
|
||||||
|
['EXPIRE', 'key', '1', 'NX']
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.expire', async client => {
|
testUtils.testWithClient('client.expire', async client => {
|
||||||
|
@@ -4,9 +4,16 @@ export const FIRST_KEY_INDEX = 1;
|
|||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
key: RedisCommandArgument,
|
key: RedisCommandArgument,
|
||||||
seconds: number
|
seconds: number,
|
||||||
|
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return ['EXPIRE', key, seconds.toString()];
|
const args = ['EXPIRE', key, seconds.toString()];
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
args.push(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { transformBooleanReply as transformReply } from './generic-transformers';
|
export { transformBooleanReply as transformReply } from './generic-transformers';
|
||||||
|
@@ -18,6 +18,13 @@ describe('EXPIREAT', () => {
|
|||||||
['EXPIREAT', 'key', Math.floor(d.getTime() / 1000).toString()]
|
['EXPIREAT', 'key', Math.floor(d.getTime() / 1000).toString()]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('with set option', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('key', 1, 'GT'),
|
||||||
|
['EXPIREAT', 'key', '1', 'GT']
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.expireAt', async client => {
|
testUtils.testWithClient('client.expireAt', async client => {
|
||||||
|
@@ -5,13 +5,20 @@ export const FIRST_KEY_INDEX = 1;
|
|||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
key: RedisCommandArgument,
|
key: RedisCommandArgument,
|
||||||
timestamp: number | Date
|
timestamp: number | Date,
|
||||||
|
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return [
|
const args = [
|
||||||
'EXPIREAT',
|
'EXPIREAT',
|
||||||
key,
|
key,
|
||||||
transformEXAT(timestamp)
|
transformEXAT(timestamp)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
args.push(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { transformBooleanReply as transformReply } from './generic-transformers';
|
export { transformBooleanReply as transformReply } from './generic-transformers';
|
||||||
|
21
packages/client/lib/commands/EXPIRETIME.spec.ts
Normal file
21
packages/client/lib/commands/EXPIRETIME.spec.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { transformArguments } from './EXPIRETIME';
|
||||||
|
|
||||||
|
describe('EXPIRETIME', () => {
|
||||||
|
testUtils.isVersionGreaterThanHook([7, 0]);
|
||||||
|
|
||||||
|
it('transformArguments', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('key'),
|
||||||
|
['EXPIRETIME', 'key']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.expireTime', async client => {
|
||||||
|
assert.equal(
|
||||||
|
await client.expireTime('key'),
|
||||||
|
-2
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
9
packages/client/lib/commands/EXPIRETIME.ts
Normal file
9
packages/client/lib/commands/EXPIRETIME.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
|
|
||||||
|
export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
|
export function transformArguments(key: RedisCommandArgument): RedisCommandArguments {
|
||||||
|
return ['EXPIRETIME', key];
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare function transformReply(): number;
|
@@ -3,11 +3,20 @@ import testUtils, { GLOBAL } from '../test-utils';
|
|||||||
import { transformArguments } from './PEXPIRE';
|
import { transformArguments } from './PEXPIRE';
|
||||||
|
|
||||||
describe('PEXPIRE', () => {
|
describe('PEXPIRE', () => {
|
||||||
it('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
assert.deepEqual(
|
it('simple', () => {
|
||||||
transformArguments('key', 1),
|
assert.deepEqual(
|
||||||
['PEXPIRE', 'key', '1']
|
transformArguments('key', 1),
|
||||||
);
|
['PEXPIRE', 'key', '1']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with set option', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('key', 1, 'GT'),
|
||||||
|
['PEXPIRE', 'key', '1', 'GT']
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.pExpire', async client => {
|
testUtils.testWithClient('client.pExpire', async client => {
|
||||||
|
@@ -4,9 +4,16 @@ export const FIRST_KEY_INDEX = 1;
|
|||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
key: RedisCommandArgument,
|
key: RedisCommandArgument,
|
||||||
milliseconds: number
|
milliseconds: number,
|
||||||
|
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return ['PEXPIRE', key, milliseconds.toString()];
|
const args = ['PEXPIRE', key, milliseconds.toString()];
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
args.push(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { transformBooleanReply as transformReply } from './generic-transformers';
|
export { transformBooleanReply as transformReply } from './generic-transformers';
|
||||||
|
@@ -18,6 +18,13 @@ describe('PEXPIREAT', () => {
|
|||||||
['PEXPIREAT', 'key', d.getTime().toString()]
|
['PEXPIREAT', 'key', d.getTime().toString()]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('with set option', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('key', 1, 'XX'),
|
||||||
|
['PEXPIREAT', 'key', '1', 'XX']
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testUtils.testWithClient('client.pExpireAt', async client => {
|
testUtils.testWithClient('client.pExpireAt', async client => {
|
||||||
|
@@ -5,13 +5,20 @@ export const FIRST_KEY_INDEX = 1;
|
|||||||
|
|
||||||
export function transformArguments(
|
export function transformArguments(
|
||||||
key: RedisCommandArgument,
|
key: RedisCommandArgument,
|
||||||
millisecondsTimestamp: number | Date
|
millisecondsTimestamp: number | Date,
|
||||||
|
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
return [
|
const args = [
|
||||||
'PEXPIREAT',
|
'PEXPIREAT',
|
||||||
key,
|
key,
|
||||||
transformPXAT(millisecondsTimestamp)
|
transformPXAT(millisecondsTimestamp)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (mode) {
|
||||||
|
args.push(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { transformBooleanReply as transformReply } from './generic-transformers';
|
export { transformBooleanReply as transformReply } from './generic-transformers';
|
||||||
|
21
packages/client/lib/commands/PEXPIRETIME.spec.ts
Normal file
21
packages/client/lib/commands/PEXPIRETIME.spec.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { transformArguments } from './PEXPIRETIME';
|
||||||
|
|
||||||
|
describe('PEXPIRETIME', () => {
|
||||||
|
testUtils.isVersionGreaterThanHook([7, 0]);
|
||||||
|
|
||||||
|
it('transformArguments', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('key'),
|
||||||
|
['PEXPIRETIME', 'key']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.pExpireTime', async client => {
|
||||||
|
assert.equal(
|
||||||
|
await client.pExpireTime('key'),
|
||||||
|
-2
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
9
packages/client/lib/commands/PEXPIRETIME.ts
Normal file
9
packages/client/lib/commands/PEXPIRETIME.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||||
|
|
||||||
|
export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
|
export function transformArguments(key: RedisCommandArgument): RedisCommandArguments {
|
||||||
|
return ['PEXPIRETIME', key];
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare function transformReply(): number;
|
Reference in New Issue
Block a user