Skip to content

Commit fcbfa1b

Browse files
committed
Added lMove, lMove$, bLMove, bLMove$ methods.
1 parent 192744e commit fcbfa1b

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

src/lib/Commands.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,64 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
20852085
}
20862086
},
20872087

2088+
/**
2089+
* Command: lMove
2090+
* @see https://redis.io/docs/latest/commands/lmove
2091+
*/
2092+
'lMove': {
2093+
prepare(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT'): IPrepareResult {
2094+
2095+
return {
2096+
cmd: 'LMOVE',
2097+
args: [srcKey, destKey, srcDir, destDir]
2098+
};
2099+
},
2100+
process: U.nullableBuffer2String
2101+
},
2102+
2103+
/**
2104+
* Command: lMove
2105+
* @see https://redis.io/docs/latest/commands/lmove
2106+
*/
2107+
'lMove$': {
2108+
prepare(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT'): IPrepareResult {
2109+
2110+
return {
2111+
cmd: 'LMOVE',
2112+
args: [srcKey, destKey, srcDir, destDir]
2113+
};
2114+
}
2115+
},
2116+
2117+
/**
2118+
* Command: bLMove
2119+
* @see https://redis.io/docs/latest/commands/blmove
2120+
*/
2121+
'bLMove': {
2122+
prepare(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT', timeout: number): IPrepareResult {
2123+
2124+
return {
2125+
cmd: 'BLMOVE',
2126+
args: [srcKey, destKey, srcDir, destDir, timeout]
2127+
};
2128+
},
2129+
process: U.nullableBuffer2String
2130+
},
2131+
2132+
/**
2133+
* Command: bLMove
2134+
* @see https://redis.io/docs/latest/commands/blmove
2135+
*/
2136+
'bLMove$': {
2137+
prepare(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT', timeout: number): IPrepareResult {
2138+
2139+
return {
2140+
cmd: 'BLMOVE',
2141+
args: [srcKey, destKey, srcDir, destDir, timeout]
2142+
};
2143+
}
2144+
},
2145+
20882146
/**
20892147
* Command: zRem
20902148
* @see https://redis.io/docs/latest/commands/zrem

src/lib/Common.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,30 @@ export interface ICommandAPIs {
12211221
*/
12221222
rPushX(key: string, values: Array<string | Buffer>): Promise<number>;
12231223

1224+
/**
1225+
* Command: lMove
1226+
* @see https://redis.io/docs/latest/commands/lmove
1227+
*/
1228+
lMove(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT'): Promise<string | null>;
1229+
1230+
/**
1231+
* Command: lMove
1232+
* @see https://redis.io/docs/latest/commands/lmove
1233+
*/
1234+
lMove$(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT'): Promise<Buffer | null>;
1235+
1236+
/**
1237+
* Command: bLMove
1238+
* @see https://redis.io/docs/latest/commands/blmove
1239+
*/
1240+
bLMove(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT', timeout: number): Promise<string | null>;
1241+
1242+
/**
1243+
* Command: bLMove
1244+
* @see https://redis.io/docs/latest/commands/blmove
1245+
*/
1246+
bLMove$(srcKey: string, destKey: string, srcDir: 'LEFT' | 'RIGHT', destDir: 'LEFT' | 'RIGHT', timeout: number): Promise<Buffer | null>;
1247+
12241248
/**
12251249
* Command: zAdd
12261250
* @see https://redis.io/docs/latest/commands/zadd

src/test/commands/blmove.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { test } from 'node:test';
2+
import * as Assert from 'node:assert';
3+
import { cmdCli } from '../common';
4+
5+
const TEST_KEY_PREFIX = 'test_hash_';
6+
7+
test('Command For Lmove/Blmove', async (t) => {
8+
9+
await cmdCli.del([...await cmdCli.keys(`${TEST_KEY_PREFIX}*`), 'any']);
10+
11+
await t.test('Append multiple items to the end of mylist', async () => {
12+
13+
Assert.strictEqual(await cmdCli.rPush(`${TEST_KEY_PREFIX}mylist`, ['one', 'two']), 2);
14+
Assert.strictEqual(await cmdCli.rPush(`${TEST_KEY_PREFIX}mylist`, ['three', 'four']), 4);
15+
16+
});
17+
18+
await t.test('Manipulate mylist using the lMove operation', async () => {
19+
20+
Assert.strictEqual(await cmdCli.lMove(`${TEST_KEY_PREFIX}mylist`, `${TEST_KEY_PREFIX}myotherlist`, 'RIGHT', 'LEFT'), 'four');
21+
22+
});
23+
24+
await t.test('Manipulate mylist using the bLMove operation', async () => {
25+
26+
Assert.strictEqual(await cmdCli.bLMove(`${TEST_KEY_PREFIX}mylist`, `${TEST_KEY_PREFIX}myotherlist`, 'LEFT', 'RIGHT', 2), 'one');
27+
28+
});
29+
30+
await t.test('Detect and remove data from mylist and myotherlist after operations', async () => {
31+
32+
Assert.deepEqual(await cmdCli.lRange(`${TEST_KEY_PREFIX}mylist`, 0, -1), ['two', 'three']);
33+
Assert.deepEqual(await cmdCli.lRange(`${TEST_KEY_PREFIX}myotherlist`,0, -1), ['four', 'one']);
34+
Assert.deepEqual(await cmdCli.lPop(`${TEST_KEY_PREFIX}mylist`, 2), ['two', 'three']);
35+
Assert.deepEqual(await cmdCli.lPop(`${TEST_KEY_PREFIX}myotherlist`, 2), ['four', 'one']);
36+
37+
});
38+
39+
await t.test('Perform the lMove operation on an empty list', async () => {
40+
41+
Assert.strictEqual(await cmdCli.lMove(`${TEST_KEY_PREFIX}mylist`, `${TEST_KEY_PREFIX}myotherlist`, 'RIGHT', 'LEFT'), null);
42+
43+
});
44+
45+
await t.test('Perform the bLMove operation on an empty list', async () => {
46+
47+
Assert.strictEqual(await cmdCli.bLMove(`${TEST_KEY_PREFIX}mylist`, `${TEST_KEY_PREFIX}myotherlist`, 'LEFT', 'RIGHT', 2), null);
48+
49+
});
50+
51+
});
52+
53+
test.after(async () => {
54+
55+
await cmdCli.close();
56+
});

0 commit comments

Comments
 (0)