Skip to content

Commit

Permalink
fix(redis): remove trailing : from base
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 8, 2023
1 parent 4fe7da7 commit 82647e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/drivers/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export default defineDriver((opts: RedisOptions = {}) => {
return redisClient;
};

const p = (key: string) => (opts.base ? `${opts.base}:${key}` : key); // Prefix a key. Uses base for backwards compatibility
const d = (key: string) => (opts.base ? key.replace(opts.base, "") : key); // Deprefix a key
const base = (opts.base || "").replace(/:$/, "");
const p = (key: string) => (base ? `${base}:${key}` : key); // Prefix a key. Uses base for backwards compatibility
const d = (key: string) => (base ? key.replace(base, "") : key); // Deprefix a key

return {
name: "redis",
Expand Down
22 changes: 20 additions & 2 deletions test/drivers/redis.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, vi } from "vitest";
import { describe, vi, it, expect } from "vitest";
import * as ioredis from "ioredis-mock";
import driver from "../../src/drivers/redis";
import { testDriver } from "./utils";
Expand All @@ -8,9 +8,27 @@ vi.mock("ioredis", () => ioredis);
describe("drivers: redis", () => {
testDriver({
driver: driver({
base: "",
base: "test:",
url: "ioredis://localhost:6379/0",
lazyConnect: false,
}),
additionalTests() {
it("should work", async () => {
const client = new ioredis.default("ioredis://localhost:6379/0");
const keys = await client.keys("*");
expect(keys).toMatchInlineSnapshot(`
[
"test:s1:a",
"test:s2:a",
"test:s3:a",
"test:data:test.json",
"test:data:true.json",
"test:data:serialized1.json",
"test:data:serialized2.json",
"test:data:raw.bin",
]
`);
});
},
});
});

0 comments on commit 82647e0

Please sign in to comment.