1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

some more commands

This commit is contained in:
Leibale
2023-05-01 06:58:27 -04:00
parent a5d0963fcf
commit 4304f4dba3
22 changed files with 354 additions and 328 deletions

View File

@@ -1,26 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './LLEN';
import LLEN from './LLEN';
describe('LLEN', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
LLEN.transformArguments('key'),
['LLEN', 'key']
);
});
testUtils.testWithClient('client.lLen', async client => {
testUtils.testAll('lLen', async client => {
assert.equal(
await client.lLen('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithCluster('cluster.lLen', async cluster => {
assert.equal(
await cluster.lLen('key'),
0
);
}, GLOBAL.CLUSTERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,28 +1,24 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './LMOVE';
import LMOVE from './LMOVE';
describe('LMOVE', () => {
testUtils.isVersionGreaterThanHook([6, 2]);
it('transformArguments', () => {
assert.deepEqual(
transformArguments('source', 'destination', 'LEFT', 'RIGHT'),
LMOVE.transformArguments('source', 'destination', 'LEFT', 'RIGHT'),
['LMOVE', 'source', 'destination', 'LEFT', 'RIGHT']
);
});
testUtils.testWithClient('client.lMove', async client => {
testUtils.testAll('lMove', async client => {
assert.equal(
await client.lMove('source', 'destination', 'LEFT', 'RIGHT'),
null
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithCluster('cluster.lMove', async cluster => {
assert.equal(
await cluster.lMove('{tag}source', '{tag}destination', 'LEFT', 'RIGHT'),
null
);
}, GLOBAL.CLUSTERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -3,6 +3,7 @@ import { ListSide } from './generic-transformers';
export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: false,
transformArguments(
source: RedisArgument,
destination: RedisArgument,

View File

@@ -1,6 +1,6 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './LMPOP';
import LMPOP from './LMPOP';
describe('LMPOP', () => {
testUtils.isVersionGreaterThanHook([7]);
@@ -8,14 +8,14 @@ describe('LMPOP', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('key', 'LEFT'),
LMPOP.transformArguments('key', 'LEFT'),
['LMPOP', '1', 'key', 'LEFT']
);
});
it('with COUNT', () => {
assert.deepEqual(
transformArguments('key', 'LEFT', {
LMPOP.transformArguments('key', 'LEFT', {
COUNT: 2
}),
['LMPOP', '1', 'key', 'LEFT', 'COUNT', '2']
@@ -23,10 +23,13 @@ describe('LMPOP', () => {
});
});
testUtils.testWithClient('client.lmPop', async client => {
testUtils.testAll('client.lmPop', async client => {
assert.deepEqual(
await client.lmPop('key', 'RIGHT'),
null
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.SERVERS.OPEN
});
});

View File

@@ -3,6 +3,7 @@ import { transformLMPopArguments, LMPopOptions, ListSide, RedisVariadicArgument
export default {
FIRST_KEY_INDEX: 2,
IS_READ_ONLY: false,
transformArguments(
keys: RedisVariadicArgument,
side: ListSide,

View File

@@ -9,11 +9,11 @@ export default {
element: RedisArgument
) {
return [
'LREM',
'LSET',
key,
index.toString(),
element
];
},
transformReply: undefined as unknown as () => SimpleStringReply
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command;

View File

@@ -8,11 +8,11 @@ export default {
stop: number
) {
return [
'LREM',
'LTRIM',
key,
start.toString(),
stop.toString()
];
},
transformReply: undefined as unknown as () => SimpleStringReply
transformReply: undefined as unknown as () => SimpleStringReply<'OK'>
} as const satisfies Command;

View File

@@ -1,11 +1,11 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MOVE';
import MOVE from './MOVE';
describe('MOVE', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 1),
MOVE.transformArguments('key', 1),
['MOVE', 'key', '1']
);
});
@@ -13,7 +13,7 @@ describe('MOVE', () => {
testUtils.testWithClient('client.move', async client => {
assert.equal(
await client.move('key', 1),
false
1
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,42 +1,38 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MSET';
import MSET from './MSET';
describe('MSET', () => {
describe('transformArguments', () => {
it("['key1', 'value1', 'key2', 'value2']", () => {
assert.deepEqual(
transformArguments(['key1', 'value1', 'key2', 'value2']),
MSET.transformArguments(['key1', 'value1', 'key2', 'value2']),
['MSET', 'key1', 'value1', 'key2', 'value2']
);
});
it("[['key1', 'value1'], ['key2', 'value2']]", () => {
assert.deepEqual(
transformArguments([['key1', 'value1'], ['key2', 'value2']]),
MSET.transformArguments([['key1', 'value1'], ['key2', 'value2']]),
['MSET', 'key1', 'value1', 'key2', 'value2']
);
});
it("{key1: 'value1'. key2: 'value2'}", () => {
assert.deepEqual(
transformArguments({ key1: 'value1', key2: 'value2' }),
MSET.transformArguments({ key1: 'value1', key2: 'value2' }),
['MSET', 'key1', 'value1', 'key2', 'value2']
);
});
});
testUtils.testWithClient('client.mSet', async client => {
testUtils.testAll('mSet', async client => {
assert.equal(
await client.mSet(['key1', 'value1', 'key2', 'value2']),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithCluster('cluster.mSet', async cluster => {
assert.equal(
await cluster.mSet(['{key}1', 'value1', '{key}2', 'value2']),
'OK'
);
}, GLOBAL.CLUSTERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,42 +1,38 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './MSETNX';
import MSETNX from './MSETNX';
describe('MSETNX', () => {
describe('transformArguments', () => {
it("['key1', 'value1', 'key2', 'value2']", () => {
assert.deepEqual(
transformArguments(['key1', 'value1', 'key2', 'value2']),
MSETNX.transformArguments(['key1', 'value1', 'key2', 'value2']),
['MSETNX', 'key1', 'value1', 'key2', 'value2']
);
});
it("[['key1', 'value1'], ['key2', 'value2']]", () => {
assert.deepEqual(
transformArguments([['key1', 'value1'], ['key2', 'value2']]),
MSETNX.transformArguments([['key1', 'value1'], ['key2', 'value2']]),
['MSETNX', 'key1', 'value1', 'key2', 'value2']
);
});
it("{key1: 'value1'. key2: 'value2'}", () => {
assert.deepEqual(
transformArguments({ key1: 'value1', key2: 'value2' }),
MSETNX.transformArguments({ key1: 'value1', key2: 'value2' }),
['MSETNX', 'key1', 'value1', 'key2', 'value2']
);
});
});
testUtils.testWithClient('client.mSetNX', async client => {
testUtils.testAll('mSetNX', async client => {
assert.equal(
await client.mSetNX(['key1', 'value1', 'key2', 'value2']),
true
await client.mSetNX(['{key}1', 'value1', '{key}2', 'value2']),
1
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithCluster('cluster.mSetNX', async cluster => {
assert.equal(
await cluster.mSetNX(['{key}1', 'value1', '{key}2', 'value2']),
true
);
}, GLOBAL.CLUSTERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PERSIST';
import PERSIST from './PERSIST';
describe('PERSIST', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
PERSIST.transformArguments('key'),
['PERSIST', 'key']
);
});
testUtils.testWithClient('client.persist', async client => {
testUtils.testAll('persist', async client => {
assert.equal(
await client.persist('key'),
false
0
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,28 +1,31 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PEXPIRE';
import PEXPIRE from './PEXPIRE';
describe('PEXPIRE', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('key', 1),
PEXPIRE.transformArguments('key', 1),
['PEXPIRE', 'key', '1']
);
});
it('with set option', () => {
assert.deepEqual(
transformArguments('key', 1, 'GT'),
PEXPIRE.transformArguments('key', 1, 'GT'),
['PEXPIRE', 'key', '1', 'GT']
);
});
});
testUtils.testWithClient('client.pExpire', async client => {
testUtils.testAll('pExpire', async client => {
assert.equal(
await client.pExpire('key', 1),
false
0
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,12 +1,12 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PEXPIREAT';
import PEXPIREAT from './PEXPIREAT';
describe('PEXPIREAT', () => {
describe('transformArguments', () => {
it('number', () => {
assert.deepEqual(
transformArguments('key', 1),
PEXPIREAT.transformArguments('key', 1),
['PEXPIREAT', 'key', '1']
);
});
@@ -14,23 +14,26 @@ describe('PEXPIREAT', () => {
it('date', () => {
const d = new Date();
assert.deepEqual(
transformArguments('key', d),
PEXPIREAT.transformArguments('key', d),
['PEXPIREAT', 'key', d.getTime().toString()]
);
});
it('with set option', () => {
assert.deepEqual(
transformArguments('key', 1, 'XX'),
PEXPIREAT.transformArguments('key', 1, 'XX'),
['PEXPIREAT', 'key', '1', 'XX']
);
});
});
testUtils.testWithClient('client.pExpireAt', async client => {
testUtils.testAll('pExpireAt', async client => {
assert.equal(
await client.pExpireAt('key', 1),
false
0
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,21 +1,24 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PEXPIRETIME';
import PEXPIRETIME from './PEXPIRETIME';
describe('PEXPIRETIME', () => {
testUtils.isVersionGreaterThanHook([7]);
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
PEXPIRETIME.transformArguments('key'),
['PEXPIRETIME', 'key']
);
});
testUtils.testWithClient('client.pExpireTime', async client => {
testUtils.testAll('pExpireTime', async client => {
assert.equal(
await client.pExpireTime('key'),
-2
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -4,7 +4,7 @@ export default {
FIRST_KEY_INDEX: 1,
IS_READ_ONLY: true,
transformArguments(key: RedisArgument) {
return ['PEXPIREAT', key];
return ['PEXPIRETIME', key];
},
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,28 +1,31 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PFADD';
import PFADD from './PFADD';
describe('PFADD', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('key', 'element'),
PFADD.transformArguments('key', 'element'),
['PFADD', 'key', 'element']
);
});
it('array', () => {
assert.deepEqual(
transformArguments('key', ['1', '2']),
PFADD.transformArguments('key', ['1', '2']),
['PFADD', 'key', '1', '2']
);
});
});
testUtils.testWithClient('client.pfAdd', async client => {
testUtils.testAll('pfAdd', async client => {
assert.equal(
await client.pfAdd('key', '1'),
true
1
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,4 +1,4 @@
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
import { RedisArgument, NumberReply, Command } from '../RESP/types';
import { RedisVariadicArgument, pushVariadicArguments } from './generic-transformers';
export default {
@@ -10,5 +10,5 @@ export default {
return pushVariadicArguments(args, element);
},
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
transformReply: undefined as unknown as () => NumberReply
} as const satisfies Command;

View File

@@ -1,28 +1,31 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PFCOUNT';
import PFCOUNT from './PFCOUNT';
describe('PFCOUNT', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('key'),
PFCOUNT.transformArguments('key'),
['PFCOUNT', 'key']
);
});
it('array', () => {
assert.deepEqual(
transformArguments(['1', '2']),
PFCOUNT.transformArguments(['1', '2']),
['PFCOUNT', '1', '2']
);
});
});
testUtils.testWithClient('client.pfCount', async client => {
testUtils.testAll('pfCount', async client => {
assert.equal(
await client.pfCount('key'),
0
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,28 +1,31 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PFMERGE';
import PFMERGE from './PFMERGE';
describe('PFMERGE', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('destination', 'source'),
PFMERGE.transformArguments('destination', 'source'),
['PFMERGE', 'destination', 'source']
);
});
it('array', () => {
assert.deepEqual(
transformArguments('destination', ['1', '2']),
PFMERGE.transformArguments('destination', ['1', '2']),
['PFMERGE', 'destination', '1', '2']
);
});
});
testUtils.testWithClient('client.pfMerge', async client => {
testUtils.testAll('pfMerge', async client => {
assert.equal(
await client.pfMerge('destination', 'source'),
await client.pfMerge('{tag}destination', '{tag}source'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,27 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PSETEX';
import PSETEX from './PSETEX';
describe('PSETEX', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 1, 'value'),
PSETEX.transformArguments('key', 1, 'value'),
['PSETEX', 'key', '1', 'value']
);
});
testUtils.testWithClient('client.pSetEx', async client => {
const a = await client.pSetEx('key', 1, 'value');
testUtils.testAll('pSetEx', async client => {
assert.equal(
await client.pSetEx('key', 1, 'value'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithCluster('cluster.pSetEx', async cluster => {
assert.equal(
await cluster.pSetEx('key', 1, 'value'),
'OK'
);
}, GLOBAL.CLUSTERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -1,19 +1,22 @@
import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './PTTL';
import PTTL from './PTTL';
describe('PTTL', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key'),
PTTL.transformArguments('key'),
['PTTL', 'key']
);
});
testUtils.testWithClient('client.pTTL', async client => {
testUtils.testAll('pTTL', async client => {
assert.equal(
await client.pTTL('key'),
-2
);
}, GLOBAL.SERVERS.OPEN);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

@@ -91,11 +91,17 @@ import LTRIM from './LTRIM';
import MGET from './MGET';
import MSET from './MSET';
import MSETNX from './MSETNX';
import PERSIST from './PERSIST';
import PEXPIRE from './PEXPIRE';
import PEXPIREAT from './PEXPIREAT';
import PEXPIRETIME from './PEXPIRETIME';
import PFADD from './PFADD';
import PFCOUNT from './PFCOUNT';
import PFMERGE from './PFMERGE';
import PING from './PING';
import PSETEX from './PSETEX';
import PTTL from './PTTL';
import RANDOMKEY from './RANDOMKEY';
import RENAME from './RENAME';
import RENAMENX from './RENAMENX';
import RPOP_COUNT from './RPOP_COUNT';
@@ -344,7 +350,15 @@ export default {
MSET,
mSet: MSET,
MSETNX,
mSetNx: MSETNX,
mSetNX: MSETNX,
PERSIST,
persist: PERSIST,
PEXPIRE,
pExpire: PEXPIRE,
PEXPIREAT,
pExpireAt: PEXPIREAT,
PEXPIRETIME,
pExpireTime: PEXPIRETIME,
PFADD,
pfAdd: PFADD,
PFCOUNT,
@@ -358,6 +372,10 @@ export default {
ping: PING,
PSETEX,
pSetEx: PSETEX,
PTTL,
pTTL: PTTL,
RANDOMKEY,
randomKey: RANDOMKEY,
RENAME,
rename: RENAME,
RENAMENX,