Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(command): fixed optional step for INCR-like commands #14

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes Logs

## v3.0.5

- fix(command): fixed optional step for `INCR-like` commands.

## v3.0.4

- fix(protocol): ensure writing network and queue in sync, avoiding disorder of execution queue.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ module.exports = [
...LitertEslintRules.configs.typescript,
{
plugins: {
'@litert/rules': require('@litert/eslint-plugin-rules'),
'@litert/rules': LitertEslintRules,
},
files: [
'src/lib/**/*.ts',
540 changes: 268 additions & 272 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@litert/redis",
"version": "3.0.4",
"version": "3.0.5",
"description": "A redis protocol implement for Node.js.",
"main": "./lib/index.js",
"scripts": {
@@ -33,12 +33,12 @@
"types": "./lib/index.d.ts",
"typings": "./lib/index.d.ts",
"devDependencies": {
"@commitlint/cli": "^19.4.1",
"@commitlint/config-conventional": "^19.4.1",
"@litert/eslint-plugin-rules": "^0.2.0",
"@types/node": "^22.5.1",
"husky": "^9.1.5",
"typescript": "^5.6.3"
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@litert/eslint-plugin-rules": "^0.2.5",
"@types/node": "^22.10.2",
"husky": "^9.1.7",
"typescript": "^5.7.2"
},
"engines": {
"node": ">=16.0.0"
2 changes: 1 addition & 1 deletion src/examples/debug.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/examples/multi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/examples/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/examples/reconnection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/lib/CommandClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
60 changes: 36 additions & 24 deletions src/lib/Commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,6 +14,8 @@
* limitations under the License.
*/

/* eslint-disable max-lines */

import * as C from './Common';
import * as U from './Utils';
import * as E from './Errors';
@@ -77,7 +79,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
},
process(data: Buffer | string): string {

return data instanceof Buffer ? data.toString() : data;
return data instanceof Buffer ? data.toString() : data as string;
}
},

@@ -146,61 +148,59 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
* @see https://redis.io/docs/latest/commands/incr
*/
'incr': {
prepare(key: string, step: number): IPrepareResult {
prepare(key: string, step: number = 1): IPrepareResult {

return {
'cmd': 'INCRBY',
'args': [key, step || 1]
'args': [key, step]
};
}
},
// process: parseInt, // always returning integer
},

/**
* Command: incrByFloat
* @see https://redis.io/docs/latest/commands/incrbyfloat
*/
'incrByFloat': {
prepare(key: string, step: number): IPrepareResult {
prepare(key: string, step: number = 1): IPrepareResult {

return {
'cmd': 'INCRBYFLOAT',
'args': [key, step]
};
},
process(data: Buffer | string): number {
return parseFloat(data as string);
}
process: parseFloat,
},

/**
* Command: decr
* @see https://redis.io/docs/latest/commands/decr
*/
'decr': {
prepare(key: string, step: number): IPrepareResult {
prepare(key: string, step: number = 1): IPrepareResult {

return {
'cmd': 'DECRBY',
'args': [key, step]
};
}
},
// process: parseInt, // always returning integer
},

/**
* Command: incrByFloat
* @see https://redis.io/docs/latest/commands/incrbyfloat
*/
'decrByFloat': {
prepare(key: string, step: number): IPrepareResult {
prepare(key: string, step: number = 1): IPrepareResult {

return {
'cmd': 'INCRBYFLOAT',
'args': [key, -step]
};
},
process(data: string | Buffer): number {
return parseFloat(data as string);
}
process: parseFloat,
},

/**
@@ -987,7 +987,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
'mSet': {
prepare(kv: Record<string, string | Buffer>): IPrepareResult {

const args: any[] = [];
const args: Array<string | Buffer> = [];

for (const k in kv) {

@@ -1010,7 +1010,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
'mSetNX': {
prepare(kv: Record<string, string | Buffer>): IPrepareResult {

const args: any[] = [];
const args: Array<string | Buffer> = [];

for (const k in kv) {

@@ -1031,37 +1031,49 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
* @see https://redis.io/docs/latest/commands/hincrby
*/
'hIncr': {
prepare: createDefaultPreparer('HINCRBY')
prepare(key: string, field: string, step: number = 1): IPrepareResult {
return {
cmd: 'HINCRBY',
args: [key, field, step]
};
},
// process: parseInt, // always returning integer
},

/**
* Command: hIncrByFloat
* @see https://redis.io/docs/latest/commands/hincrbyfloat
*/
'hIncrByFloat': {
prepare: createDefaultPreparer('HINCRBYFLOAT'),
process: parseFloat
prepare(key: string, field: string, step: number = 1): IPrepareResult {
return {
cmd: 'HINCRBYFLOAT',
args: [key, field, step]
};
},
process: parseFloat,
},

/**
* Command: hIncr
* @see https://redis.io/docs/latest/commands/hincrby
*/
'hDecr': {
prepare(key: string, field: string, step: number): IPrepareResult {
prepare(key: string, field: string, step: number = 1): IPrepareResult {
return {
cmd: 'HINCRBY',
args: [key, field, -(step || 1)]
args: [key, field, -step]
};
}
},
// process: parseInt, // always returning integer
},

/**
* Command: hIncrByFloat
* @see https://redis.io/docs/latest/commands/hincrbyfloat
*/
'hDecrByFloat': {
prepare(key: string, field: string, step: number): IPrepareResult {
prepare(key: string, field: string, step: number = 1): IPrepareResult {
return {
cmd: 'HINCRBYFLOAT',
args: [key, field, -step]
59 changes: 48 additions & 11 deletions src/lib/Common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable max-lines */
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -388,27 +389,43 @@ export interface ICommandAPIs {

/**
* Command: incr
*
* @param key The key of the hash.
* @param increment The step to increase. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/incr
*/
incr(key: string, step?: number): Promise<number>;
incr(key: string, increment?: number): Promise<number>;

/**
* Command: incrByFloat
*
* @param key The key of the hash.
* @param increment The step to increase. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/incrbyfloat
*/
incrByFloat(key: string, step: number): Promise<number>;
incrByFloat(key: string, increment?: number): Promise<number>;

/**
* Command: decr
*
* @param key The key of the hash.
* @param decrement The step to decrease. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/decr
*/
decr(key: string, step?: number): Promise<number>;
decr(key: string, decrement?: number): Promise<number>;

/**
* Command: incrByFloat
*
* @param key The key of the hash.
* @param decrement The step to decrease. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/incrbyfloat
*/
decrByFloat(key: string, step: number): Promise<number>;
decrByFloat(key: string, decrement?: number): Promise<number>;

/**
* Command: del
@@ -815,27 +832,47 @@ export interface ICommandAPIs {

/**
* Command: hIncr
*
* @param key The key of the hash.
* @param field The field of the hash.
* @param increment The step to increase. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/hincrby
*/
hIncr(key: string, field: string, step?: number): Promise<number>;
hIncr(key: string, field: string, increment?: number): Promise<number>;

/**
* Command: hIncr
* Command: hIncrByFloat
*
* @param key The key of the hash.
* @param field The field of the hash.
* @param increment The step to increase. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/hincrbyfloat
*/
hIncrByFloat(key: string, field: string, step: number): Promise<number>;
hIncrByFloat(key: string, field: string, increment?: number): Promise<number>;

/**
* Command: hIncr
*
* @param key The key of the hash.
* @param field The field of the hash.
* @param decrement The step to decrease. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/hincrby
*/
hDecr(key: string, field: string, step?: number): Promise<number>;
hDecr(key: string, field: string, decrement?: number): Promise<number>;

/**
* Command: hIncr
* Command: hIncrByFloat
*
* @param key The key of the hash.
* @param field The field of the hash.
* @param decrement The step to decrease. [Default: 1]
*
* @see https://redis.io/docs/latest/commands/hincrbyfloat
*/
hDecrByFloat(key: string, field: string, step: number): Promise<number>;
hDecrByFloat(key: string, field: string, decrement?: number): Promise<number>;

/**
* Command: hKeys
2 changes: 1 addition & 1 deletion src/lib/Constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/lib/Decoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/lib/Encoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/lib/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
2 changes: 1 addition & 1 deletion src/lib/ModuleAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2024 Angus.Fenying <fenying@litert.org>
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Loading
Oops, something went wrong.