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 EXPIRE from '../commands/EXPIRE';
|
||||
import * as EXPIREAT from '../commands/EXPIREAT';
|
||||
import * as EXPIRETIME from '../commands/EXPIRETIME';
|
||||
import * as GEOADD from '../commands/GEOADD';
|
||||
import * as GEODIST from '../commands/GEODIST';
|
||||
import * as GEOHASH from '../commands/GEOHASH';
|
||||
@@ -75,6 +76,7 @@ import * as MSETNX from '../commands/MSETNX';
|
||||
import * as PERSIST from '../commands/PERSIST';
|
||||
import * as PEXPIRE from '../commands/PEXPIRE';
|
||||
import * as PEXPIREAT from '../commands/PEXPIREAT';
|
||||
import * as PEXPIRETIME from '../commands/PEXPIRETIME';
|
||||
import * as PFADD from '../commands/PFADD';
|
||||
import * as PFCOUNT from '../commands/PFCOUNT';
|
||||
import * as PFMERGE from '../commands/PFMERGE';
|
||||
@@ -224,6 +226,8 @@ export default {
|
||||
expire: EXPIRE,
|
||||
EXPIREAT,
|
||||
expireAt: EXPIREAT,
|
||||
EXPIRETIME,
|
||||
expireTime: EXPIRETIME,
|
||||
GEOADD,
|
||||
geoAdd: GEOADD,
|
||||
GEODIST,
|
||||
@@ -332,6 +336,8 @@ export default {
|
||||
pExpire: PEXPIRE,
|
||||
PEXPIREAT,
|
||||
pExpireAt: PEXPIREAT,
|
||||
PEXPIRETIME,
|
||||
pExpireTime: PEXPIRETIME,
|
||||
PFADD,
|
||||
pfAdd: PFADD,
|
||||
PFCOUNT,
|
||||
|
@@ -3,13 +3,22 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './EXPIRE';
|
||||
|
||||
describe('EXPIRE', () => {
|
||||
it('transformArguments', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
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 => {
|
||||
assert.equal(
|
||||
await client.expire('key', 0),
|
||||
|
@@ -4,9 +4,16 @@ export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
seconds: number
|
||||
seconds: number,
|
||||
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||
): 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';
|
||||
|
@@ -18,6 +18,13 @@ describe('EXPIREAT', () => {
|
||||
['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 => {
|
||||
|
@@ -5,13 +5,20 @@ export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
timestamp: number | Date
|
||||
timestamp: number | Date,
|
||||
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||
): RedisCommandArguments {
|
||||
return [
|
||||
const args = [
|
||||
'EXPIREAT',
|
||||
key,
|
||||
transformEXAT(timestamp)
|
||||
];
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
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,13 +3,22 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { transformArguments } from './PEXPIRE';
|
||||
|
||||
describe('PEXPIRE', () => {
|
||||
it('transformArguments', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
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 => {
|
||||
assert.equal(
|
||||
await client.pExpire('key', 1),
|
||||
|
@@ -4,9 +4,16 @@ export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
milliseconds: number
|
||||
milliseconds: number,
|
||||
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||
): 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';
|
||||
|
@@ -18,6 +18,13 @@ describe('PEXPIREAT', () => {
|
||||
['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 => {
|
||||
|
@@ -5,13 +5,20 @@ export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
millisecondsTimestamp: number | Date
|
||||
millisecondsTimestamp: number | Date,
|
||||
mode?: 'NX' | 'XX' | 'GT' | 'LT'
|
||||
): RedisCommandArguments {
|
||||
return [
|
||||
const args = [
|
||||
'PEXPIREAT',
|
||||
key,
|
||||
transformPXAT(millisecondsTimestamp)
|
||||
];
|
||||
|
||||
if (mode) {
|
||||
args.push(mode);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
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