@stacksjs/cache 0.38.3 → 0.38.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/Memcached.spec.d.ts +1 -0
- package/dist/__tests__/Memcached.spec.mjs +37 -0
- package/dist/__tests__/Redis.spec.d.ts +1 -0
- package/dist/__tests__/Redis.spec.mjs +59 -0
- package/dist/drivers/memcached.d.ts +4 -0
- package/dist/drivers/memcached.mjs +13 -0
- package/dist/drivers/redis.d.ts +3 -1
- package/dist/drivers/redis.mjs +5 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +2 -1
- package/package.json +9 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Memcached from "memjs";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
const client = Memcached.Client.create("127.0.0.1:11211");
|
|
4
|
+
async function set(key, value, duration) {
|
|
5
|
+
await client.set(key, value, { expires: duration });
|
|
6
|
+
}
|
|
7
|
+
async function get(key) {
|
|
8
|
+
const value = await client.get(key);
|
|
9
|
+
const result = value.value ? value.value.toString() : null;
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
async function del(key) {
|
|
13
|
+
await client.delete(key);
|
|
14
|
+
}
|
|
15
|
+
async function flush() {
|
|
16
|
+
await client.flush();
|
|
17
|
+
}
|
|
18
|
+
describe("MemcachedTest", () => {
|
|
19
|
+
it("it should set memcached cache", async () => {
|
|
20
|
+
await set("test", "test", 10 * 60);
|
|
21
|
+
expect(await get("test")).toBe("test");
|
|
22
|
+
});
|
|
23
|
+
it("it should get memcached cache", async () => {
|
|
24
|
+
await set("test", "test", 10 * 60);
|
|
25
|
+
expect(await get("test")).toBe("test");
|
|
26
|
+
});
|
|
27
|
+
it("it should delete memcached cache", async () => {
|
|
28
|
+
await set("test", "test", 10 * 60);
|
|
29
|
+
await del("test");
|
|
30
|
+
expect(await get("test")).toBe(null);
|
|
31
|
+
});
|
|
32
|
+
it("it should flush memcached cache", async () => {
|
|
33
|
+
await set("test", "test", 10 * 60);
|
|
34
|
+
await flush();
|
|
35
|
+
expect(await get("test")).toBe(null);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createClient } from "redis";
|
|
3
|
+
const client = createClient({
|
|
4
|
+
socket: {
|
|
5
|
+
host: "127.0.0.1",
|
|
6
|
+
port: 6379
|
|
7
|
+
},
|
|
8
|
+
password: ""
|
|
9
|
+
});
|
|
10
|
+
await client.connect();
|
|
11
|
+
async function set(key, value) {
|
|
12
|
+
await client.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
async function get(key) {
|
|
15
|
+
const value = await client.get(key);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
async function remove(key) {
|
|
19
|
+
await client.del(key);
|
|
20
|
+
}
|
|
21
|
+
async function del(key) {
|
|
22
|
+
await client.del(key);
|
|
23
|
+
}
|
|
24
|
+
async function flushAll() {
|
|
25
|
+
await client.sendCommand(["FLUSHALL", "ASYNC"]);
|
|
26
|
+
}
|
|
27
|
+
async function flushDB() {
|
|
28
|
+
await client.sendCommand(["FLUSHDB", "ASYNC"]);
|
|
29
|
+
}
|
|
30
|
+
describe("RedisTest", () => {
|
|
31
|
+
it("it should set redis cache", async () => {
|
|
32
|
+
await set("test", "test");
|
|
33
|
+
expect(await get("test")).toBe("test");
|
|
34
|
+
});
|
|
35
|
+
it("it should get redis cache", async () => {
|
|
36
|
+
await set("test", "test");
|
|
37
|
+
expect(await get("test")).toBe("test");
|
|
38
|
+
});
|
|
39
|
+
it("it should remove cache", async () => {
|
|
40
|
+
await set("test", "test");
|
|
41
|
+
await remove("test");
|
|
42
|
+
expect(await get("test")).toBe(null);
|
|
43
|
+
});
|
|
44
|
+
it("it should del cache", async () => {
|
|
45
|
+
await set("test", "test");
|
|
46
|
+
await del("test");
|
|
47
|
+
expect(await get("test")).toBe(null);
|
|
48
|
+
});
|
|
49
|
+
it("it should flush all cache", async () => {
|
|
50
|
+
await set("test", "test");
|
|
51
|
+
await flushAll();
|
|
52
|
+
expect(await get("test")).toBe(null);
|
|
53
|
+
});
|
|
54
|
+
it("it should flush all DB", async () => {
|
|
55
|
+
await set("test", "test");
|
|
56
|
+
await flushDB();
|
|
57
|
+
expect(await get("test")).toBe(null);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Memcached } from "memjs";
|
|
2
|
+
const client = Memcached.Client.create("127.0.0.1:11211");
|
|
3
|
+
async function set(key, value, duration) {
|
|
4
|
+
await client.set(key, value, { expires: duration });
|
|
5
|
+
}
|
|
6
|
+
async function get(key) {
|
|
7
|
+
const value = await client.get(key);
|
|
8
|
+
return value.value.toString();
|
|
9
|
+
}
|
|
10
|
+
async function del(key) {
|
|
11
|
+
await client.delete(key);
|
|
12
|
+
}
|
|
13
|
+
export { set, get, del };
|
package/dist/drivers/redis.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { RedisClientType } from 'redis';
|
|
2
|
+
declare const client: RedisClientType;
|
|
1
3
|
declare function set(key: any, value: any): Promise<void>;
|
|
2
4
|
declare function get(key: string): Promise<any>;
|
|
3
5
|
declare function remove(key: string): Promise<void>;
|
|
4
6
|
declare function del(key: string): Promise<void>;
|
|
5
7
|
declare function flushAll(): Promise<void>;
|
|
6
8
|
declare function flushDB(): Promise<void>;
|
|
7
|
-
export { set, get, remove, del, flushAll, flushDB };
|
|
9
|
+
export { set, get, remove, del, flushAll, flushDB, client };
|
package/dist/drivers/redis.mjs
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
import { createClient } from "redis";
|
|
2
2
|
import { cache } from "@stacksjs/config";
|
|
3
3
|
const client = createClient({
|
|
4
|
-
|
|
4
|
+
socket: {
|
|
5
|
+
host: cache.redis.host,
|
|
6
|
+
port: cache.redis.port
|
|
7
|
+
},
|
|
5
8
|
password: ""
|
|
6
9
|
});
|
|
7
10
|
await client.connect();
|
|
8
11
|
async function set(key, value) {
|
|
9
12
|
await client.set(key, value);
|
|
10
|
-
await client.disconnect();
|
|
11
13
|
}
|
|
12
14
|
async function get(key) {
|
|
13
15
|
const value = await client.get(key);
|
|
14
|
-
await client.disconnect();
|
|
15
16
|
return value;
|
|
16
17
|
}
|
|
17
18
|
async function remove(key) {
|
|
18
19
|
await client.del(key);
|
|
19
|
-
await client.disconnect();
|
|
20
20
|
}
|
|
21
21
|
async function del(key) {
|
|
22
22
|
await client.del(key);
|
|
23
|
-
await client.disconnect();
|
|
24
23
|
}
|
|
25
24
|
async function flushAll() {
|
|
26
25
|
await client.sendCommand(["FLUSHALL", "ASYNC"]);
|
|
27
|
-
await client.disconnect();
|
|
28
26
|
}
|
|
29
27
|
async function flushDB() {
|
|
30
28
|
await client.sendCommand(["FLUSHDB", "ASYNC"]);
|
|
31
|
-
await client.disconnect();
|
|
32
29
|
}
|
|
33
|
-
export { set, get, remove, del, flushAll, flushDB };
|
|
30
|
+
export { set, get, remove, del, flushAll, flushDB, client };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './drivers/redis';
|
|
1
|
+
export * as redis from './drivers/redis';
|
|
2
|
+
export * as memcached from './drivers/memcached';
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./drivers/redis.mjs";
|
|
1
|
+
export * as redis from "./drivers/redis.mjs";
|
|
2
|
+
export * as memcached from "./drivers/memcached.mjs";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/cache",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.38.
|
|
4
|
+
"version": "0.38.4",
|
|
5
5
|
"packageManager": "pnpm@7.15.0",
|
|
6
6
|
"description": "The Stacks way to test.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
@@ -39,13 +39,19 @@
|
|
|
39
39
|
"pnpm": ">=7.15.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@stacksjs/config": "0.38.
|
|
42
|
+
"@stacksjs/config": "0.38.4",
|
|
43
|
+
"memcached": "^2.2.2",
|
|
43
44
|
"redis": "^4.5.0",
|
|
44
45
|
"vitest": "^0.25.1"
|
|
45
46
|
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"memcached": "^2.2.2",
|
|
49
|
+
"memjs": "^1.3.0"
|
|
50
|
+
},
|
|
46
51
|
"devDependencies": {
|
|
47
52
|
"mkdist": "^0.4.0",
|
|
48
|
-
"typescript": "^4.8.4"
|
|
53
|
+
"typescript": "^4.8.4",
|
|
54
|
+
"vitest": "^0.25.1"
|
|
49
55
|
},
|
|
50
56
|
"scripts": {
|
|
51
57
|
"build": "mkdist -d",
|