Skip to content
This repository has been archived by the owner on Nov 22, 2018. It is now read-only.

Commit

Permalink
feat(hincrbyfloat): adds validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshmali committed Aug 9, 2017
1 parent d48152f commit 4b7f0c5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/commands/hincrbyfloat.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export function hincrbyfloat(key: string, field: string, increment: string) {
if (increment == null) {
throw new Error('Wrong number of arguments specified');
}
const hash = this.data.get(key) || { [field]: '0' };
if (!{}.hasOwnProperty.call(hash, field)) {
hash[field] = '0';
}
const curVal = parseFloat(hash[field]);
if (isNaN(curVal)) {
throw new Error('Hash value is not a number');
}
hash[field] = (curVal + parseFloat(increment)).toString();
this.data.set(key, hash);
return hash[field];
Expand Down

0 comments on commit 4b7f0c5

Please sign in to comment.