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-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 testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SDIFF';
import SDIFF from './SDIFF';
describe('SDIFF', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('key'),
['SDIFF', 'key']
);
});
it('array', () => {
assert.deepEqual(
transformArguments(['1', '2']),
['SDIFF', '1', '2']
);
});
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
SDIFF.transformArguments('key'),
['SDIFF', 'key']
);
});
testUtils.testWithClient('client.sDiff', async client => {
assert.deepEqual(
await client.sDiff('key'),
[]
);
}, GLOBAL.SERVERS.OPEN);
it('array', () => {
assert.deepEqual(
SDIFF.transformArguments(['1', '2']),
['SDIFF', '1', '2']
);
});
});
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 testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SDIFFSTORE';
import SDIFFSTORE from './SDIFFSTORE';
describe('SDIFFSTORE', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('destination', 'key'),
['SDIFFSTORE', 'destination', 'key']
);
});
it('array', () => {
assert.deepEqual(
transformArguments('destination', ['1', '2']),
['SDIFFSTORE', 'destination', '1', '2']
);
});
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
SDIFFSTORE.transformArguments('destination', 'key'),
['SDIFFSTORE', 'destination', 'key']
);
});
testUtils.testWithClient('client.sDiffStore', async client => {
assert.equal(
await client.sDiffStore('destination', 'key'),
0
);
}, GLOBAL.SERVERS.OPEN);
it('array', () => {
assert.deepEqual(
SDIFFSTORE.transformArguments('destination', ['1', '2']),
['SDIFFSTORE', 'destination', '1', '2']
);
});
});
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 testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SET';
import SET from './SET';
describe('SET', () => {
describe('transformArguments', () => {
it('string', () => {
assert.deepEqual(
transformArguments('key', 'value'),
['SET', 'key', 'value']
);
});
it('number', () => {
assert.deepEqual(
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('transformArguments', () => {
describe('value', () => {
it('string', () => {
assert.deepEqual(
SET.transformArguments('key', 'value'),
['SET', 'key', 'value']
);
});
it('number', () => {
assert.deepEqual(
SET.transformArguments('key', 0),
['SET', 'key', '0']
);
});
});
describe('client.set', () => {
testUtils.testWithClient('simple', async client => {
assert.equal(
await client.set('key', 'value'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
describe('expiration', () => {
it('with expiration', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
expiration: {
type: 'EX',
value: 0
}
}),
['SET', 'key', 'value', 'EX', '0']
);
});
testUtils.testWithClient('with GET on empty key', async client => {
assert.equal(
await client.set('key', 'value', {
GET: true
}),
null
);
}, {
...GLOBAL.SERVERS.OPEN,
minimumDockerVersion: [6, 2]
});
it('with EX (backwards compatibility)', () => {
assert.deepEqual(
SET.transformArguments('key', 'value', {
EX: 0
}),
['SET', 'key', 'value', 'EX', '0']
);
});
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 testUtils, { GLOBAL } from '../test-utils';
import { transformArguments } from './SETBIT';
import SETBIT from './SETBIT';
describe('SETBIT', () => {
it('transformArguments', () => {
assert.deepEqual(
transformArguments('key', 0, 1),
['SETBIT', 'key', '0', '1']
);
});
it('transformArguments', () => {
assert.deepEqual(
SETBIT.transformArguments('key', 0, 1),
['SETBIT', 'key', '0', '1']
);
});
testUtils.testWithClient('client.setBit', async client => {
assert.equal(
await client.setBit('key', 0, 1),
0
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithCluster('cluster.setBit', async cluster => {
assert.equal(
await cluster.setBit('key', 0, 1),
0
);
}, GLOBAL.CLUSTERS.OPEN);
testUtils.testAll('setBit', async client => {
assert.equal(
await client.setBit('key', 0, 1),
0
);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});

View File

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

View File

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

View File

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

View File

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