forked from redis/ioredis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cluster): fix autopipeline with keyPrefix or arg array
Previously, the building of pipelines ignored the key prefix. It was possible that two keys, foo and bar, might be set into the same pipeline. However, after being prefixed by a configured "keyPrefix" value, they may no longer belong to the same pipeline. This led to the error: "All keys in the pipeline should belong to the same slots allocation group" Similarly, `args[0]` can be a (possibly empty) array which the Command constructor would flatten. Properly compute the first flattened key when autopipelining for a Redis.Cluster instance. Amended version of https://github.com/luin/ioredis/pull/1335/files - see comments on that PR This may fix redis#1264 and redis#1248. Fixes redis#1392
- Loading branch information
1 parent
beefcc1
commit 36f6387
Showing
7 changed files
with
140 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import defaults = require("lodash.defaults"); | ||
import flatten = require("lodash.flatten"); | ||
import isArguments = require("lodash.isarguments"); | ||
|
||
export function noop() {} | ||
|
||
export { defaults, flatten }; | ||
export { defaults, flatten, isArguments }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect } from "chai"; | ||
import { getFirstValueInFlattenedArray } from "../../lib/autoPipelining"; | ||
import { flatten } from "../../lib/utils/lodash"; | ||
|
||
describe("autoPipelining", function () { | ||
const expectGetFirstValueIs = (values, expected) => { | ||
expect(getFirstValueInFlattenedArray(values)).to.eql(expected); | ||
// getFirstValueInFlattenedArray should behave the same way as flatten(args)[0] | ||
// but be much more efficient. | ||
expect(flatten(values)[0]).to.eql(expected); | ||
}; | ||
|
||
it("should be able to efficiently get array args", function () { | ||
expectGetFirstValueIs([], undefined); | ||
expectGetFirstValueIs([null, "key"], null); | ||
expectGetFirstValueIs(["key", "value"], "key"); | ||
expectGetFirstValueIs([[], "key"], "key"); | ||
expectGetFirstValueIs([["key"]], "key"); | ||
// @ts-ignore | ||
expectGetFirstValueIs([[["key"]]], ["key"]); | ||
// @ts-ignore | ||
expectGetFirstValueIs([0, 1, 2, 3, 4], 0); | ||
// @ts-ignore | ||
expectGetFirstValueIs([[true]], true); | ||
// @ts-ignore | ||
expectGetFirstValueIs([Buffer.from("test")], Buffer.from("test")); | ||
// @ts-ignore | ||
expectGetFirstValueIs([{}], {}); | ||
// lodash.isArguments is true for this legacy js way to get argument lists | ||
const createArguments = function () { | ||
return arguments; | ||
}; | ||
// @ts-ignore | ||
expectGetFirstValueIs([createArguments(), createArguments("key")], "key"); | ||
// @ts-ignore | ||
expectGetFirstValueIs([createArguments("")], ""); | ||
}); | ||
}); |