1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

some more commands

This commit is contained in:
Leibale
2023-04-30 10:08:25 -04:00
parent 2c4dc95a44
commit 53b9397a78
8 changed files with 259 additions and 243 deletions

View File

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

View File

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

View File

@@ -1,63 +1,77 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import testUtils, { GLOBAL } from '../test-utils'; import testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SET'; import SET from './SET';
describe('SET', () => { describe('SET', () => {
describe('transformArguments', () => { describe('transformArguments', () => {
describe('value', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value'), SET.transformArguments('key', 'value'),
['SET', 'key', 'value'] ['SET', 'key', 'value']
); );
}); });
it('number', () => { it('number', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 0), SET.transformArguments('key', 0),
['SET', 'key', '0'] ['SET', 'key', '0']
); );
}); });
});
describe('TTL', () => { describe('expiration', () => {
it('with EX', () => { it('with expiration', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
expiration: {
type: 'EX',
value: 0
}
}),
['SET', 'key', 'value', 'EX', '0']
);
});
it('with EX (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
EX: 0 EX: 0
}), }),
['SET', 'key', 'value', 'EX', '0'] ['SET', 'key', 'value', 'EX', '0']
); );
}); });
it('with PX', () => { it('with PX (backwards compatibility)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
PX: 0 PX: 0
}), }),
['SET', 'key', 'value', 'PX', '0'] ['SET', 'key', 'value', 'PX', '0']
); );
}); });
it('with EXAT', () => { it('with EXAT (backwards compatibility)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
EXAT: 0 EXAT: 0
}), }),
['SET', 'key', 'value', 'EXAT', '0'] ['SET', 'key', 'value', 'EXAT', '0']
); );
}); });
it('with PXAT', () => { it('with PXAT (backwards compatibility)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
PXAT: 0 PXAT: 0
}), }),
['SET', 'key', 'value', 'PXAT', '0'] ['SET', 'key', 'value', 'PXAT', '0']
); );
}); });
it('with KEEPTTL', () => { it('with KEEPTTL (backwards compatibility)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
KEEPTTL: true KEEPTTL: true
}), }),
['SET', 'key', 'value', 'KEEPTTL'] ['SET', 'key', 'value', 'KEEPTTL']
@@ -65,19 +79,28 @@ describe('SET', () => {
}); });
}); });
describe('Guards', () => { describe('condition', () => {
it('with NX', () => { it('with condition', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
condition: 'NX'
}),
['SET', 'key', 'value', 'NX']
);
});
it('with NX (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
NX: true NX: true
}), }),
['SET', 'key', 'value', 'NX'] ['SET', 'key', 'value', 'NX']
); );
}); });
it('with XX', () => { it('with XX (backwards compatibility)', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
XX: true XX: true
}), }),
['SET', 'key', 'value', 'XX'] ['SET', 'key', 'value', 'XX']
@@ -87,43 +110,35 @@ describe('SET', () => {
it('with GET', () => { it('with GET', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
GET: true GET: true
}), }),
['SET', 'key', 'value', 'GET'] ['SET', 'key', 'value', 'GET']
); );
}); });
it('with EX, NX, GET', () => { it('with expiration, condition, GET', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'value', { SET.transformArguments('key', 'value', {
EX: 1, expiration: {
NX: true, type: 'EX',
value: 0
},
condition: 'NX',
GET: true GET: true
}), }),
['SET', 'key', 'value', 'EX', '1', 'NX', 'GET'] ['SET', 'key', 'value', 'EX', '0', 'NX', 'GET']
); );
}); });
}); });
describe('client.set', () => { testUtils.testAll('set', async client => {
testUtils.testWithClient('simple', async client => {
assert.equal( assert.equal(
await client.set('key', 'value'), await client.set('key', 'value'),
'OK' 'OK'
); );
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('with GET on empty key', async client => {
assert.equal(
await client.set('key', 'value', {
GET: true
}),
null
);
}, { }, {
...GLOBAL.SERVERS.OPEN, client: GLOBAL.SERVERS.OPEN,
minimumDockerVersion: [6, 2] cluster: GLOBAL.CLUSTERS.OPEN
});
}); });
}); });

View File

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

View File

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

View File

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

View File

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

View File

@@ -99,7 +99,10 @@ import RPOPLPUSH from './RPOPLPUSH';
import RPUSH from './RPUSH'; import RPUSH from './RPUSH';
import RPUSHX from './RPUSHX'; import RPUSHX from './RPUSHX';
import SCAN from './SCAN'; import SCAN from './SCAN';
import SDIFF from './SDIFF';
import SDIFFSTORE from './SDIFFSTORE';
import SET from './SET'; import SET from './SET';
import SETBIT from './SETBIT';
import SETEX from './SETEX'; import SETEX from './SETEX';
import SETNX from './SETNX'; import SETNX from './SETNX';
import SETRANGE from './SETRANGE'; import SETRANGE from './SETRANGE';
@@ -354,12 +357,20 @@ export default {
rPushX: RPUSHX, rPushX: RPUSHX,
SCAN, SCAN,
scan: SCAN, scan: SCAN,
SDIFF,
sDiff: SDIFF,
SDIFFSTORE,
sDiffStore: SDIFFSTORE,
SET, SET,
set: SET, set: SET,
SETBIT,
setBit: SETBIT,
SETEX, SETEX,
setEx: SETEX, setEx: SETEX,
SETNX, SETNX,
setNx: SETNX, setNX: SETNX,
SETRANGE,
setRange: SETRANGE,
SINTER, SINTER,
sInter: SINTER, sInter: SINTER,
SINTERCARD, SINTERCARD,