Skip to content

Commit

Permalink
refactor: reuse the args logic of hset and hmset (#1257)
Browse files Browse the repository at this point in the history
`hset` and `hmset` have the same logic when processing parameter conversion, so use the same function variable to reuse the same processing.
  • Loading branch information
Jiasm authored Mar 14, 2021
1 parent 4ba66ad commit d7af532
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions lib/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,7 @@ const msetArgumentTransformer = function (args) {
return args;
};

Command.setArgumentTransformer("mset", msetArgumentTransformer);
Command.setArgumentTransformer("msetnx", msetArgumentTransformer);

Command.setArgumentTransformer("hmset", function (args) {
const hsetArgumentTransformer = function (args) {
if (args.length === 2) {
if (typeof Map !== "undefined" && args[1] instanceof Map) {
return [args[0]].concat(convertMapToArray(args[1]));
Expand All @@ -395,7 +392,13 @@ Command.setArgumentTransformer("hmset", function (args) {
}
}
return args;
});
}

Command.setArgumentTransformer("mset", msetArgumentTransformer);
Command.setArgumentTransformer("msetnx", msetArgumentTransformer);

Command.setArgumentTransformer("hset", hsetArgumentTransformer);
Command.setArgumentTransformer("hmset", hsetArgumentTransformer);

Command.setReplyTransformer("hgetall", function (result) {
if (Array.isArray(result)) {
Expand All @@ -408,18 +411,6 @@ Command.setReplyTransformer("hgetall", function (result) {
return result;
});

Command.setArgumentTransformer("hset", function (args) {
if (args.length === 2) {
if (typeof Map !== "undefined" && args[1] instanceof Map) {
return [args[0]].concat(convertMapToArray(args[1]));
}
if (typeof args[1] === "object" && args[1] !== null) {
return [args[0]].concat(convertObjectToArray(args[1]));
}
}
return args;
});

class MixedBuffers {
length = 0;
items = [];
Expand Down

0 comments on commit d7af532

Please sign in to comment.