1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-10 11:43:01 +03:00
Files
node-redis/lib/commands/SET.spec.ts
Leibale Eidelman e592d9403d v4.0.0-rc.2 (#1664)
* update workflows & README

* add .deepsource.toml

* fix client.quit, add error events on cluster, fix some "deepsource.io" warnings

* Release 4.0.0-rc.1

* add cluster.duplicate, add some tests

* fix #1650 - add support for Buffer in some commands, add GET_BUFFER command

* fix GET and GET_BUFFER return type

* update FAQ

* Update invalid code example in README.md (#1654)

* Update invalid code example in README.md

* Update README.md

Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>

* fix #1652

* ref #1653 - better types

* better types

* fix 54124793ad

* Update GEOSEARCHSTORE.spec.ts

* fix #1660 - add support for client.HSET('key', 'field', 'value')

* upgrade dependencies, update README

* fix #1659 - add support for db-number in client options url

* fix README, remove unused import, downgrade typedoc & typedoc-plugin-markdown

* update client-configurations.md

* fix README

* add CLUSTER_SLOTS, add some tests

* fix "createClient with url" test with redis 5

* remove unused imports

* Release 4.0.0-rc.2

Co-authored-by: Richard Samuelsson <noobtoothfairy@gmail.com>
2021-09-23 16:36:40 -04:00

122 lines
3.5 KiB
TypeScript

import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient } from '../test-utils';
import { transformArguments } from './SET';
describe('SET', () => {
describe('transformArguments', () => {
it('simple', () => {
assert.deepEqual(
transformArguments('key', 'value'),
['SET', 'key', 'value']
);
});
describe('TTL', () => {
it('with EX', () => {
assert.deepEqual(
transformArguments('key', 'value', {
EX: 1
}),
['SET', 'key', 'value', 'EX', '1']
);
});
it('with PX', () => {
assert.deepEqual(
transformArguments('key', 'value', {
PX: 1
}),
['SET', 'key', 'value', 'PX', '1']
);
});
it('with EXAT', () => {
assert.deepEqual(
transformArguments('key', 'value', {
EXAT: 1
}),
['SET', 'key', 'value', 'EXAT', '1']
);
});
it('with PXAT', () => {
assert.deepEqual(
transformArguments('key', 'value', {
PXAT: 1
}),
['SET', 'key', 'value', 'PXAT', '1']
);
});
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', () => {
itWithClient(TestRedisServers.OPEN, 'simple', async client => {
assert.equal(
await client.set('key', 'value'),
'OK'
);
});
itWithClient(TestRedisServers.OPEN, 'with GET on empty key', async client => {
assert.equal(
await client.set('key', 'value', {
GET: true
}),
null
);
}, {
minimumRedisVersion: [6, 2]
});
});
});