Skip to content

Commit 758c861

Browse files
committed
fix(command): fixed command LPOP and RPOP
1 parent d74d3ae commit 758c861

22 files changed

+47
-43
lines changed

.vscode/launch.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"program": "${workspaceFolder}/src/examples/debug.ts",
1212
"sourceMaps": true,
1313
"outFiles": [
14-
"${workspaceFolder}/{lib,examples}/*.js"
14+
"${workspaceFolder}/**/*.js"
1515
]
1616
},
1717
{
@@ -21,7 +21,7 @@
2121
"program": "${workspaceFolder}/src/examples/multi.ts",
2222
"sourceMaps": true,
2323
"outFiles": [
24-
"${workspaceFolder}/{lib,examples}/*.js"
24+
"${workspaceFolder}/**/*.js"
2525
]
2626
},
2727
{
@@ -31,7 +31,7 @@
3131
"program": "${workspaceFolder}/src/examples/pipeline.ts",
3232
"sourceMaps": true,
3333
"outFiles": [
34-
"${workspaceFolder}/{lib,examples}/*.js"
34+
"${workspaceFolder}/**/*.js"
3535
]
3636
},
3737
{
@@ -41,7 +41,7 @@
4141
"program": "${workspaceFolder}/src/examples/reconnection.ts",
4242
"sourceMaps": true,
4343
"outFiles": [
44-
"${workspaceFolder}/{lib,examples}/*.js"
44+
"${workspaceFolder}/**/*.js"
4545
]
4646
}
4747
]

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes Logs
22

3+
## v2.0.2
4+
5+
- fix(command): fixed command `lpop` and `rpop`.
6+
37
## v2.0.1
48

59
- fix(connection): refactored connection management

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@litert/redis",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "A redis protocol implement for Node.js.",
55
"main": "./lib/index.js",
66
"scripts": {

src/examples/debug.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Angus.Fenying <[email protected]>
2+
* Copyright 2023 Angus.Fenying <[email protected]>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -75,14 +75,22 @@ import * as Redis from '../lib';
7575
console.log(await cli.hRandFieldWithValues('aaaa', 2));
7676
console.log(await cli.hRandFieldWithValues$('aaaa', 2));
7777

78-
await cli.rPush('list-test', ['1', '2', '3', '4', '5']);
79-
console.log(await cli.lPop('list-test'));
78+
await cli.rPush('list-test', ['1', '2', '23', '345', '4567', '5']);
8079
console.log(await cli.lPop('list-test', 1));
80+
console.log(await cli.lPop('list-test'));
8181
console.log(await cli.lPop('list-test', 4));
8282
console.log(await cli.lPop('list-test'));
8383
console.log(await cli.lPop('list-test', 4));
8484

85+
await cli.rPush('list-test', ['1', '2', '23', '345', '4567', '5']);
86+
console.log(await cli.lPop$('list-test', 1));
87+
console.log(await cli.lPop$('list-test'));
88+
console.log(await cli.lPop$('list-test', 4));
89+
console.log(await cli.lPop$('list-test'));
90+
console.log(await cli.lPop$('list-test', 4));
91+
8592
await cli.close();
93+
await sub.close();
8694
return;
8795

8896
console.log('PING ->', await cli.ping(''));

src/examples/multi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Angus.Fenying <[email protected]>
2+
* Copyright 2023 Angus.Fenying <[email protected]>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/examples/pipeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Angus.Fenying <[email protected]>
2+
* Copyright 2023 Angus.Fenying <[email protected]>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/examples/reconnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Angus.Fenying <[email protected]>
2+
* Copyright 2023 Angus.Fenying <[email protected]>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/lib/CommandClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Angus.Fenying <[email protected]>
2+
* Copyright 2023 Angus.Fenying <[email protected]>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/lib/Commands.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Angus.Fenying <[email protected]>
2+
* Copyright 2023 Angus.Fenying <[email protected]>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1890,11 +1890,9 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
18901890
},
18911891
process(data: any, args: any[]): string | null | string[] {
18921892

1893-
switch (data?.length ?? 0) {
1894-
case 0:
1895-
return args[1] ? [] : null;
1893+
switch (args.length) {
18961894
case 1:
1897-
return args[1] ? [data[0][1].toString()] : data.toString();
1895+
return data?.toString() ?? null;
18981896
default:
18991897
return U.list2StringList(data);
19001898
}
@@ -1915,11 +1913,9 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
19151913
},
19161914
process(data: any, args: any[]): Buffer | null | Buffer[] {
19171915

1918-
switch (data?.length ?? 0) {
1919-
case 0:
1920-
return args[1] ? [] : null;
1916+
switch (args.length) {
19211917
case 1:
1922-
return args[1] ? [data[0][1]] : data;
1918+
return data ?? null;
19231919
default:
19241920
return U.list2BufferList(data);
19251921
}
@@ -2012,11 +2008,9 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
20122008
},
20132009
process(data: any, args: any[]): string | null | string[] {
20142010

2015-
switch (data?.length ?? 0) {
2016-
case 0:
2017-
return args[1] ? [] : null;
2011+
switch (args.length) {
20182012
case 1:
2019-
return args[1] ? [data[0][1].toString()] : data.toString();
2013+
return data?.toString() ?? null;
20202014
default:
20212015
return U.list2StringList(data);
20222016
}
@@ -2037,11 +2031,9 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
20372031
},
20382032
process(data: any, args: any[]): Buffer | null | Buffer[] {
20392033

2040-
switch (data?.length ?? 0) {
2041-
case 0:
2042-
return args[1] ? [] : null;
2034+
switch (args.length) {
20432035
case 1:
2044-
return args[1] ? [data[0][1]] : data;
2036+
return data ?? null;
20452037
default:
20462038
return U.list2BufferList(data);
20472039
}

0 commit comments

Comments
 (0)