Browse Source
Merge pull request #7594 from Budibase/fix/redis-connector
improvements to redis connector - multi line pipelines and lowercase …
pull/7647/head
Martin McKeaveney
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
32 additions and
7 deletions
-
packages/server/src/integrations/redis.ts
-
packages/server/src/integrations/tests/redis.spec.js
|
|
|
@ -132,12 +132,22 @@ module RedisModule { |
|
|
|
|
|
|
|
async command(query: { json: string }) { |
|
|
|
return this.redisContext(async () => { |
|
|
|
const commands = query.json.trim().split(" ") |
|
|
|
const pipeline = this.client.pipeline([commands]) |
|
|
|
const result = await pipeline.exec() |
|
|
|
return { |
|
|
|
response: result[0][1], |
|
|
|
// commands split line by line
|
|
|
|
const commands = query.json.trim().split("\n") |
|
|
|
let pipelineCommands = [] |
|
|
|
|
|
|
|
// process each command separately
|
|
|
|
for (let command of commands) { |
|
|
|
const tokenised = command.trim().split(" ") |
|
|
|
// Pipeline only accepts lower case commands
|
|
|
|
tokenised[0] = tokenised[0].toLowerCase() |
|
|
|
pipelineCommands.push(tokenised) |
|
|
|
} |
|
|
|
|
|
|
|
const pipeline = this.client.pipeline(pipelineCommands) |
|
|
|
const result = await pipeline.exec() |
|
|
|
|
|
|
|
return result.map((output: string | string[]) => output[1]) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -46,7 +46,7 @@ describe("Redis Integration", () => { |
|
|
|
expect(await config.redis.get(body.key)).toEqual(null) |
|
|
|
}) |
|
|
|
|
|
|
|
it("calls the command method with the correct params", async () => { |
|
|
|
it("calls the pipeline method with the correct params", async () => { |
|
|
|
const body = { |
|
|
|
json: "KEYS *" |
|
|
|
} |
|
|
|
@ -55,6 +55,21 @@ describe("Redis Integration", () => { |
|
|
|
config.integration.client.pipeline = jest.fn(() => ({ exec: jest.fn(() => [[]]) })) |
|
|
|
|
|
|
|
await config.integration.command(body) |
|
|
|
expect(config.integration.client.pipeline).toHaveBeenCalledWith([["KEYS", "*"]]) |
|
|
|
expect(config.integration.client.pipeline).toHaveBeenCalledWith([["keys", "*"]]) |
|
|
|
}) |
|
|
|
|
|
|
|
it("calls the pipeline method with several separated commands when there are newlines", async () => { |
|
|
|
const body = { |
|
|
|
json: 'SET foo "bar"\nGET foo' |
|
|
|
} |
|
|
|
|
|
|
|
// ioredis-mock doesn't support pipelines
|
|
|
|
config.integration.client.pipeline = jest.fn(() => ({ exec: jest.fn(() => [[]]) })) |
|
|
|
|
|
|
|
await config.integration.command(body) |
|
|
|
expect(config.integration.client.pipeline).toHaveBeenCalledWith([ |
|
|
|
["set", 'foo', '"bar"'], |
|
|
|
["get", 'foo'] |
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |