-
Notifications
You must be signed in to change notification settings - Fork 65
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
added hincrBy and hincrByFloat in node #502
Conversation
node/src/BaseClient.ts
Outdated
@@ -447,6 +451,44 @@ export class BaseClient { | |||
return this.createWritePromise(createHMGet(key, fields)); | |||
} | |||
|
|||
/** Increments the number stored at field in the hash stored at key by increment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
field => `field`
key => `key`
by increment => by `amount`.
node/src/BaseClient.ts
Outdated
* | ||
* @param key - The key of the hash. | ||
* @param amount - The amount to increment. | ||
* @param field - The field in the hash stored at key to increment it's value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's => its
node/src/BaseClient.ts
Outdated
* @param key - The key of the hash. | ||
* @param amount - The amount to increment. | ||
* @param field - The field in the hash stored at key to increment it's value. | ||
* @returns the value of the field in the hash stored at key after the increment, An error is returned if the key contains a value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the value of the field in the hash stored at key after the increment.
An error will be returned if the key holds a value of an incorrect type (not a string) or if it contains a string that cannot be represented as an integer.
node/src/BaseClient.ts
Outdated
} | ||
|
||
/** Increment the string representing a floating point number stored at field in the hash stored at key by increment. | ||
* By using a negative increment value, the result is that the value stored at field in the hash stored at key is decremented. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it relevant also for hincrBy?
node/src/BaseClient.ts
Outdated
return this.createWritePromise(createHIncrBy(key, field, amount)); | ||
} | ||
|
||
/** Increment the string representing a floating point number stored at field in the hash stored at key by increment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for marking the variables with ``
node/src/Transaction.ts
Outdated
@@ -312,6 +316,38 @@ export class BaseTransaction { | |||
this.commands.push(createHMGet(key, fields)); | |||
} | |||
|
|||
/** Increments the number stored at field in the hash stored at key by increment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for all comments from BaseClient
key: string, | ||
field: string, | ||
amount: number | ||
): Promise<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why incrbyfloat returns a string and incrby returns number? I would expect both to return a number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we talked about it: It's because RESP2 doesn't support double/float numbers so it returns as a string.
lets leave it as a string for now, and add the command to this issue:
#504
change the headline to
Change return type of several commands for types introduced in RESP3
and edit the content so it would have a table of the command, its current return type, and the required type to change to after we'll have support in RESP3
node/tests/SharedTests.ts
Outdated
}; | ||
expect(await client.hset(key, fieldValueMap)).toEqual(1); | ||
expect(await client.hincrBy(key, field, 1)).toEqual(11); | ||
expect(await client.hget(key, field)).toEqual("11"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to check it also with hget, it is enough to verify that the return result of hincrBy is the expected result. Please fix in all places
node/tests/SharedTests.ts
Outdated
await runTest(async (client: BaseClient) => { | ||
const key1 = uuidv4(); | ||
const key2 = uuidv4(); | ||
const nonExistingKey1 = uuidv4(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nonExistingKey1 -> can be changed to nonExistingKey, if there's no nonExistingKey2, right?
node/tests/SharedTests.ts
Outdated
); | ||
|
||
it( | ||
"hincrBy and hincrByFloat with a field that contains a value of string that can not be represented as integer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as integer or float
5d394d0
to
b0619f6
Compare
@barshaul ready for another round. |
b0619f6
to
8798b86
Compare
Description of changes:
added hincrBy and hincrByFloat in node