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', () => {
assert.deepEqual(
transformArguments(['1', '2']),
['SDIFF', '1', '2']
);
});
}); });
testUtils.testWithClient('client.sDiff', async client => { it('array', () => {
assert.deepEqual( assert.deepEqual(
await client.sDiff('key'), SDIFF.transformArguments(['1', '2']),
[] ['SDIFF', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('sDiff', async client => {
assert.deepEqual(
await client.sDiff('key'),
[]
);
}, {
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', () => {
assert.deepEqual(
transformArguments('destination', ['1', '2']),
['SDIFFSTORE', 'destination', '1', '2']
);
});
}); });
testUtils.testWithClient('client.sDiffStore', async client => { it('array', () => {
assert.equal( assert.deepEqual(
await client.sDiffStore('destination', 'key'), SDIFFSTORE.transformArguments('destination', ['1', '2']),
0 ['SDIFFSTORE', 'destination', '1', '2']
); );
}, GLOBAL.SERVERS.OPEN); });
});
testUtils.testAll('sDiffStore', async client => {
assert.equal(
await client.sDiffStore('{tag}destination', '{tag}key'),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
}); });

View File

@@ -1,129 +1,144 @@
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', () => {
it('string', () => { describe('value', () => {
assert.deepEqual( it('string', () => {
transformArguments('key', 'value'), assert.deepEqual(
['SET', 'key', 'value'] SET.transformArguments('key', 'value'),
); ['SET', 'key', 'value']
}); );
});
it('number', () => {
assert.deepEqual( it('number', () => {
transformArguments('key', 0), assert.deepEqual(
['SET', 'key', '0'] SET.transformArguments('key', 0),
); ['SET', 'key', '0']
}); );
});
describe('TTL', () => {
it('with EX', () => {
assert.deepEqual(
transformArguments('key', 'value', {
EX: 0
}),
['SET', 'key', 'value', 'EX', '0']
);
});
it('with PX', () => {
assert.deepEqual(
transformArguments('key', 'value', {
PX: 0
}),
['SET', 'key', 'value', 'PX', '0']
);
});
it('with EXAT', () => {
assert.deepEqual(
transformArguments('key', 'value', {
EXAT: 0
}),
['SET', 'key', 'value', 'EXAT', '0']
);
});
it('with PXAT', () => {
assert.deepEqual(
transformArguments('key', 'value', {
PXAT: 0
}),
['SET', 'key', 'value', 'PXAT', '0']
);
});
it('with KEEPTTL', () => {
assert.deepEqual(
transformArguments('key', 'value', {
KEEPTTL: true
}),
['SET', 'key', 'value', 'KEEPTTL']
);
});
});
describe('Guards', () => {
it('with NX', () => {
assert.deepEqual(
transformArguments('key', 'value', {
NX: true
}),
['SET', 'key', 'value', 'NX']
);
});
it('with XX', () => {
assert.deepEqual(
transformArguments('key', 'value', {
XX: true
}),
['SET', 'key', 'value', 'XX']
);
});
});
it('with GET', () => {
assert.deepEqual(
transformArguments('key', 'value', {
GET: true
}),
['SET', 'key', 'value', 'GET']
);
});
it('with EX, NX, GET', () => {
assert.deepEqual(
transformArguments('key', 'value', {
EX: 1,
NX: true,
GET: true
}),
['SET', 'key', 'value', 'EX', '1', 'NX', 'GET']
);
});
}); });
describe('client.set', () => { describe('expiration', () => {
testUtils.testWithClient('simple', async client => { it('with expiration', () => {
assert.equal( assert.deepEqual(
await client.set('key', 'value'), SET.transformArguments('key', 'value', {
'OK' expiration: {
); type: 'EX',
}, GLOBAL.SERVERS.OPEN); value: 0
}
}),
['SET', 'key', 'value', 'EX', '0']
);
});
testUtils.testWithClient('with GET on empty key', async client => { it('with EX (backwards compatibility)', () => {
assert.equal( assert.deepEqual(
await client.set('key', 'value', { SET.transformArguments('key', 'value', {
GET: true EX: 0
}), }),
null ['SET', 'key', 'value', 'EX', '0']
); );
}, { });
...GLOBAL.SERVERS.OPEN,
minimumDockerVersion: [6, 2] it('with PX (backwards compatibility)', () => {
}); assert.deepEqual(
SET.transformArguments('key', 'value', {
PX: 0
}),
['SET', 'key', 'value', 'PX', '0']
);
});
it('with EXAT (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
EXAT: 0
}),
['SET', 'key', 'value', 'EXAT', '0']
);
});
it('with PXAT (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
PXAT: 0
}),
['SET', 'key', 'value', 'PXAT', '0']
);
});
it('with KEEPTTL (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
KEEPTTL: true
}),
['SET', 'key', 'value', 'KEEPTTL']
);
});
}); });
describe('condition', () => {
it('with condition', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
condition: 'NX'
}),
['SET', 'key', 'value', 'NX']
);
});
it('with NX (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
NX: true
}),
['SET', 'key', 'value', 'NX']
);
});
it('with XX (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
XX: true
}),
['SET', 'key', 'value', 'XX']
);
});
});
it('with GET', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
GET: true
}),
['SET', 'key', 'value', 'GET']
);
});
it('with expiration, condition, GET', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
expiration: {
type: 'EX',
value: 0
},
condition: 'NX',
GET: true
}),
['SET', 'key', 'value', 'EX', '0', 'NX', 'GET']
);
});
});
testUtils.testAll('set', async client => {
assert.equal(
await client.set('key', 'value'),
'OK'
);
}, {
client: GLOBAL.SERVERS.OPEN,
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,