@joker.server/redis 1.0.3 → 1.0.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/bundle.js +1 -1
- package/package.json +13 -8
- package/types/index.d.ts +2 -2
package/dist/bundle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("redis");function e(t,e){return`${t}:${e}`}exports.RedisCache=class{client;constructor(e){this.client=t.createClient(e)}async expire(t,e,a){await(this.client?.expire(t,e))}async incrBy(t,e){return await(this.client?.incrBy(t,e))}async incrByFloat(t,e){let a=await(this.client?.incrByFloat(t,e));return Number(a)}async setHashValue(t,e,a,i){let s=JSON.stringify(a);i?await this.client.hSetNX(t,e,s):await this.client.hSet(t,e,s)}async getHashValue(t,e){let a=await this.client.hGet(t,e);if(a)return JSON.parse(a)}async getHashAll(t){let e=await this.client.hGetAll(t);for(let t in e)e[t]=JSON.parse(e[t]);return e}async deleteHashValue(t,e){await this.client.hDel(t,e)}getHashKeys(t){return this.client.hKeys(t)}async hasHashKey(t,e){return 1===await this.client.hExists(t,e)}incrHashBy(t,e,a){return this.client.hIncrBy(t,e,a)}async incrHashByFloat(t,e,a){let i=await(this.client?.hIncrByFloat(t,e,a));return Number(i)}clearHash(t){return this.delete(t)}async clearAll(){await this.client.flushDb()}async get(t){let e=await this.client.get(t);if(e)return JSON.parse(e)}async set(t,e,a,i){let s=JSON.stringify(e);i?await this.client.setNX(t,s):await this.client.set(t,s),a&&this.client.expire(t,a)}async delete(t){await this.client.del(t)}async exists(t){return await this.client.exists(t)>0}async arrayPush(t,...e){let a=e.map((t=>JSON.stringify(t)));await this.client.rPush(t,a)}async arraySlice(t,e,a){return(await this.client.lRange(t,e,a)).map((t=>JSON.parse(t)))}async arrayItem(t,e){let a=await this.client.lIndex(t,e);if(null!==a)return JSON.parse(a)}async arrayLength(t){return await this.client.lLen(t)}setMapValue(t,a,i,s,n){let r=e(t,a);return this.set(r,i,s,n)}async setMapValues(t,a,i,s){let n={};for(let i in a){n[e(t,i)]=JSON.stringify(a[i])}if(s?await this.client.mSetNX(n):await this.client.mSet(n),i)for(let t in n)this.client.expire(t,i)}getMapValue(t,a){let i=e(t,a);return this.get(i)}async getMapValues(t,a){return(await this.client.mGet(a.map((a=>e(t,a))))).map((t=>{if(t)return JSON.parse(t)}))}deleteMapValue(t,a){let i=e(t,a);return this.delete(i)}async getMapKeys(t){return(await this.client.keys(`${t}:*`)).map((e=>e.substring(t.length+1)))}hasMapKey(t,a){let i=e(t,a);return this.exists(i)}async clearMap(t){let e=await this.getMapKeys(t);for(let t of e)this.delete(t)}};
|
|
1
|
+
"use strict";var t=require("redis");function e(t,e){return`${t}:${e}`}exports.RedisCache=class{client;constructor(e){this.client=t.createClient(e)}async expire(t,e,a){await(this.client?.expire(t,e))}async incrBy(t,e){return await(this.client?.incrBy(t,e))}async incrByFloat(t,e){let a=await(this.client?.incrByFloat(t,e));return Number(a)}async setHashValue(t,e,a,i){let s=JSON.stringify(a);i?await this.client.hSetNX(t,e,s):await this.client.hSet(t,e,s)}async getHashValue(t,e){let a=await this.client.hGet(t,e);if(a)return JSON.parse(a)}async getHashAll(t){let e=await this.client.hGetAll(t);for(let t in e)e[t]=JSON.parse(e[t]);return e}async deleteHashValue(t,e){await this.client.hDel(t,e)}getHashKeys(t){return this.client.hKeys(t)}async hasHashKey(t,e){return 1===await this.client.hExists(t,e)}incrHashBy(t,e,a){return this.client.hIncrBy(t,e,a)}async incrHashByFloat(t,e,a){let i=await(this.client?.hIncrByFloat(t,e,a));return Number(i)}clearHash(t){return this.delete(t)}async clearAll(){await this.client.flushDb()}async get(t){let e=await this.client.get(t);if(e)return JSON.parse(e)}async set(t,e,a,i){let s=JSON.stringify(e),n=!1;return i?n=!!await this.client.setNX(t,s):(await this.client.set(t,s),n=!0),a&&this.client.expire(t,a),n}async delete(t){await this.client.del(t)}async exists(t){return await this.client.exists(t)>0}async arrayPush(t,...e){let a=e.map((t=>JSON.stringify(t)));await this.client.rPush(t,a)}async arraySlice(t,e,a){return(await this.client.lRange(t,e,a)).map((t=>JSON.parse(t)))}async arrayItem(t,e){let a=await this.client.lIndex(t,e);if(null!==a)return JSON.parse(a)}async arrayLength(t){return await this.client.lLen(t)}setMapValue(t,a,i,s,n){let r=e(t,a);return this.set(r,i,s,n)}async setMapValues(t,a,i,s){let n={};for(let i in a){n[e(t,i)]=JSON.stringify(a[i])}if(s?await this.client.mSetNX(n):await this.client.mSet(n),i)for(let t in n)this.client.expire(t,i)}getMapValue(t,a){let i=e(t,a);return this.get(i)}async getMapValues(t,a){return(await this.client.mGet(a.map((a=>e(t,a))))).map((t=>{if(t)return JSON.parse(t)}))}deleteMapValue(t,a){let i=e(t,a);return this.delete(i)}async getMapKeys(t){return(await this.client.keys(`${t}:*`)).map((e=>e.substring(t.length+1)))}hasMapKey(t,a){let i=e(t,a);return this.exists(i)}async clearMap(t){let e=await this.getMapKeys(t);for(let t of e)this.delete(t)}};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joker.server/redis",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Joker 服务端 Redis 缓存方案插件",
|
|
5
5
|
"main": "dist/bundle.js",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "rm -rf types &&
|
|
9
|
-
"build:prod": "
|
|
10
|
-
"release": "npm run build &&
|
|
8
|
+
"build": "rm -rf types && node build/index.js",
|
|
9
|
+
"build:prod": "rm -rf types && node build/index.js --terser --sourcemap=false",
|
|
10
|
+
"release": "npm run build && npm publish",
|
|
11
11
|
"release:prod": "npm run build:prod && npm publish --access public --registry https://registry.npmjs.org/"
|
|
12
12
|
},
|
|
13
13
|
"author": "Zohar",
|
|
@@ -18,12 +18,17 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@joker.
|
|
22
|
-
"@joker.server/core": "^1.0.159",
|
|
21
|
+
"@joker.server/core": "^1.0.186",
|
|
23
22
|
"@joker.front/shared": "^1.5.30",
|
|
24
|
-
"typescript": "^5.
|
|
23
|
+
"typescript": "^5.8.3",
|
|
24
|
+
"rollup": "^4.45.1",
|
|
25
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
26
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
27
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
28
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
29
|
+
"@rollup/plugin-terser": "^0.4.4"
|
|
25
30
|
},
|
|
26
31
|
"dependencies": {
|
|
27
|
-
"redis": "^5.
|
|
32
|
+
"redis": "^5.10.0"
|
|
28
33
|
}
|
|
29
34
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -17,14 +17,14 @@ export declare class RedisCache implements ICache {
|
|
|
17
17
|
clearHash(key: string): Promise<any>;
|
|
18
18
|
clearAll(): Promise<void>;
|
|
19
19
|
get(key: string): Promise<any>;
|
|
20
|
-
set(key: string, value: any, expire: number | undefined, setnx?: boolean | undefined): Promise<
|
|
20
|
+
set(key: string, value: any, expire: number | undefined, setnx?: boolean | undefined): Promise<boolean>;
|
|
21
21
|
delete(key: string): Promise<void>;
|
|
22
22
|
exists(key: string): Promise<boolean>;
|
|
23
23
|
arrayPush(key: string, ...values: any[]): Promise<void>;
|
|
24
24
|
arraySlice(key: string, start: number, end: number): Promise<any[]>;
|
|
25
25
|
arrayItem(key: string, index: number): Promise<any>;
|
|
26
26
|
arrayLength(key: string): Promise<number>;
|
|
27
|
-
setMapValue(key: string, id: string, value: any, expire: number | undefined, setnx?: boolean | undefined): Promise<
|
|
27
|
+
setMapValue(key: string, id: string, value: any, expire: number | undefined, setnx?: boolean | undefined): Promise<boolean>;
|
|
28
28
|
setMapValues(key: string, values: Record<string, any>, expire: number | undefined, setnx?: boolean | undefined): Promise<void>;
|
|
29
29
|
getMapValue(key: string, id: string): Promise<any>;
|
|
30
30
|
getMapValues(key: string, ids: string[]): Promise<any[]>;
|