@yongdall/cache-redis 0.1.0
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/hooks.yongdall.mjs +10 -0
- package/hooks.yongdall.mjs.map +1 -0
- package/index.d.mts +6 -0
- package/index.mjs +6 -0
- package/index.mjs.map +1 -0
- package/package.json +22 -0
- package/redis-Bwl20g_X.mjs +38 -0
- package/redis-Bwl20g_X.mjs.map +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import redis from "#index";
|
|
2
|
+
|
|
3
|
+
//#region providers/cache-redis/hooks.yongdall.mjs
|
|
4
|
+
/** @import { Hooks } from '@yongdall/connection' */
|
|
5
|
+
/** @type {Hooks.providers} */
|
|
6
|
+
const providers = { cache: { redis } };
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { providers };
|
|
10
|
+
//# sourceMappingURL=hooks.yongdall.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../providers/cache-redis/hooks.yongdall.mjs"],"sourcesContent":["import redis from '#index';\n/** @import { Hooks } from '@yongdall/connection' */\n/** @type {Hooks.providers} */\nexport const providers = {\n\tcache: { redis },\n};\n"],"mappings":";;;;;AAGA,MAAa,YAAY,EACxB,OAAO,EAAE,OAAO,EAChB"}
|
package/index.d.mts
ADDED
package/index.mjs
ADDED
package/index.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../providers/cache-redis/index.mjs"],"sourcesContent":["export default (/** @type {string} */url) => import('./redis.mjs').then(v => v.default(url));\n"],"mappings":";AAAA,2BAAqC,QAAQ,OAAO,wBAAe,MAAK,MAAK,EAAE,QAAQ,IAAI,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yongdall/cache-redis",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./index.mjs",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.mjs"
|
|
7
|
+
},
|
|
8
|
+
"imports": {
|
|
9
|
+
"#index": "./index.mjs"
|
|
10
|
+
},
|
|
11
|
+
"version": "0.1.0",
|
|
12
|
+
"description": "",
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"ioredis": "^5.4.1"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@yongdall/connection": "^0.1.0"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import IORedis from "ioredis";
|
|
2
|
+
|
|
3
|
+
//#region providers/cache-redis/redis.mjs
|
|
4
|
+
/** @import { Cache } from '@yongdall/connection' */
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} url
|
|
8
|
+
* @returns {Promise<Cache>}
|
|
9
|
+
*/
|
|
10
|
+
async function redis_default(url) {
|
|
11
|
+
const redis = new IORedis(url);
|
|
12
|
+
return {
|
|
13
|
+
async set(key, field, value) {
|
|
14
|
+
await redis.hset(key, field, JSON.stringify(value));
|
|
15
|
+
},
|
|
16
|
+
async exists(key, field) {
|
|
17
|
+
return redis.hexists(key, field).then((v) => Boolean(v));
|
|
18
|
+
},
|
|
19
|
+
async del(key, field) {
|
|
20
|
+
await redis.hdel(key, field);
|
|
21
|
+
},
|
|
22
|
+
async clear(key) {
|
|
23
|
+
await redis.del(key);
|
|
24
|
+
},
|
|
25
|
+
async get(key, field) {
|
|
26
|
+
const data = await redis.hget(key, field);
|
|
27
|
+
if (!data) return;
|
|
28
|
+
return JSON.parse(data);
|
|
29
|
+
},
|
|
30
|
+
disconnect() {
|
|
31
|
+
redis.disconnect();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { redis_default as default };
|
|
38
|
+
//# sourceMappingURL=redis-Bwl20g_X.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redis-Bwl20g_X.mjs","names":[],"sources":["../../providers/cache-redis/redis.mjs"],"sourcesContent":["import IORedis from 'ioredis';\n/** @import { Cache } from '@yongdall/connection' */\n\n/**\n * \n * @param {string} url \n * @returns {Promise<Cache>}\n */\nexport default async function (url) {\n\tconst redis = new IORedis(url);\n\treturn {\n\t\tasync set(key, field, value) {\n\t\t\tawait redis.hset(key, field, JSON.stringify(value));\n\t\t},\n\t\tasync exists(key, field) {\n\t\t\treturn redis.hexists(key, field).then(v => Boolean(v));\n\t\t},\n\t\tasync del(key, field) {\n\t\t\tawait redis.hdel(key, field);\n\t\t},\n\t\tasync clear(key) {\n\t\t\tawait redis.del(key);\n\t\t},\n\t\tasync get(key, field) {\n\t\t\tconst data = await redis.hget(key, field);\n\t\t\tif (!data) { return ; }\n\t\t\treturn JSON.parse(data);\n\t\t},\n\t\tdisconnect() {\n\t\t\tredis.disconnect();\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;AAQA,6BAA+B,KAAK;CACnC,MAAM,QAAQ,IAAI,QAAQ,IAAI;AAC9B,QAAO;EACN,MAAM,IAAI,KAAK,OAAO,OAAO;AAC5B,SAAM,MAAM,KAAK,KAAK,OAAO,KAAK,UAAU,MAAM,CAAC;;EAEpD,MAAM,OAAO,KAAK,OAAO;AACxB,UAAO,MAAM,QAAQ,KAAK,MAAM,CAAC,MAAK,MAAK,QAAQ,EAAE,CAAC;;EAEvD,MAAM,IAAI,KAAK,OAAO;AACrB,SAAM,MAAM,KAAK,KAAK,MAAM;;EAE7B,MAAM,MAAM,KAAK;AAChB,SAAM,MAAM,IAAI,IAAI;;EAErB,MAAM,IAAI,KAAK,OAAO;GACrB,MAAM,OAAO,MAAM,MAAM,KAAK,KAAK,MAAM;AACzC,OAAI,CAAC,KAAQ;AACb,UAAO,KAAK,MAAM,KAAK;;EAExB,aAAa;AACZ,SAAM,YAAY;;EAEnB"}
|