@ohos-ports/keyv-memcache 0.0.0-stage → 2.0.2-beta.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/LICENSE +22 -0
- package/README.md +142 -2
- package/dist/index.cjs +157 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +122 -0
- package/package.json +86 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2021 Luke Childs
|
|
4
|
+
Copyright (c) 2021-2022 Jared Wray
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,143 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @keyv/memcache [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Memcache storage adapter for [Keyv](https://github.com/jaredwray/keyv)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[](https://github.com/jaredwray/keyv/actions/workflows/tests.yaml)
|
|
7
|
+
[](https://codecov.io/gh/jaredwray/keyv)
|
|
8
|
+
[](https://github.com/jaredwray/keyv/blob/main/LICENSE)
|
|
9
|
+
[](https://npmjs.com/package/@keyv/memcache)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
npm install --save @keyv/memcache
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Keyv Compression is not Supported
|
|
18
|
+
|
|
19
|
+
This package does not support compression. If you need compression, please use the `@keyv/redis` or another service package instead.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import Keyv from 'keyv';
|
|
25
|
+
import KeyvMemcache from '@keyv/memcache';
|
|
26
|
+
|
|
27
|
+
const memcache = new KeyvMemcache('user:pass@localhost:11211');
|
|
28
|
+
const keyv = new Keyv({ store: memcache });
|
|
29
|
+
|
|
30
|
+
//set
|
|
31
|
+
await keyv.set("foo","bar", 6000) //Expiring time is optional
|
|
32
|
+
|
|
33
|
+
//get
|
|
34
|
+
const obj = await keyv.get("foo");
|
|
35
|
+
|
|
36
|
+
//delete
|
|
37
|
+
await keyv.delete("foo");
|
|
38
|
+
|
|
39
|
+
//clear
|
|
40
|
+
await keyv.clear();
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage with Namespaces
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import Keyv from 'keyv';
|
|
48
|
+
import KeyvMemcache from '@keyv/memcache';
|
|
49
|
+
|
|
50
|
+
const memcache = new KeyvMemcache('user:pass@localhost:11211');
|
|
51
|
+
const keyv1 = new Keyv({ store: memcache, namespace: "namespace1" });
|
|
52
|
+
const keyv2 = new Keyv({ store: memcache, namespace: "namespace2" });
|
|
53
|
+
|
|
54
|
+
//set
|
|
55
|
+
await keyv1.set("foo","bar1", 6000) //Expiring time is optional
|
|
56
|
+
await keyv2.set("foo","bar2", 6000) //Expiring time is optional
|
|
57
|
+
|
|
58
|
+
//get
|
|
59
|
+
const obj1 = await keyv1.get("foo"); //will return bar1
|
|
60
|
+
const obj2 = await keyv2.get("foo"); //will return bar2
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
# Works with Memcached, Memcachier, Redislabs, and Google Cloud
|
|
65
|
+
|
|
66
|
+
## Using Memcached
|
|
67
|
+
|
|
68
|
+
1. Install Memcached and start an instance
|
|
69
|
+
```js
|
|
70
|
+
|
|
71
|
+
//set the server to the correct address and port
|
|
72
|
+
const server = "localhost:11211"
|
|
73
|
+
|
|
74
|
+
const Keyv = require("keyv");
|
|
75
|
+
const KeyvMemcache = require("@keyv/memcache");
|
|
76
|
+
|
|
77
|
+
const memcache = new KeyvMemcache(server);
|
|
78
|
+
const keyv = new Keyv({ store: memcache});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Using Memcachier
|
|
82
|
+
|
|
83
|
+
1. Go to https://www.memcachier.com and signup
|
|
84
|
+
2. Create a cache and setup where.
|
|
85
|
+
3. In the screen take the username, password, and url and place it into your code:
|
|
86
|
+
```js
|
|
87
|
+
|
|
88
|
+
//best practice is to not hard code your config in code.
|
|
89
|
+
const user = "";
|
|
90
|
+
const pass = "";
|
|
91
|
+
const server = "XXX.XXX.XXX.memcachier.com:11211"
|
|
92
|
+
|
|
93
|
+
const Keyv = require("keyv");
|
|
94
|
+
const KeyvMemcache = require("@keyv/memcache");
|
|
95
|
+
|
|
96
|
+
const memcache = new KeyvMemcache(user +":"+ pass +"@"+ server);
|
|
97
|
+
const keyv = new Keyv({ store: memcache});
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Using Redislabs Memcache Protocol
|
|
102
|
+
|
|
103
|
+
1. Go to https://www.redislabs.com and signup
|
|
104
|
+
2. Create a database and make sure to set the `Protocol` to memcached
|
|
105
|
+
3. In the screen take the username, password, and `endpoint` (the server) and place it into your code:
|
|
106
|
+
```js
|
|
107
|
+
|
|
108
|
+
//best practice is to not hard code your config in code.
|
|
109
|
+
const user = "";
|
|
110
|
+
const pass = "";
|
|
111
|
+
const server = "XXX.XXX.XXX.XXX.cloud.redislabs.com:XXX"
|
|
112
|
+
|
|
113
|
+
const Keyv = require("keyv");
|
|
114
|
+
const KeyvMemcache = require("@keyv/memcache");
|
|
115
|
+
|
|
116
|
+
const memcache = new KeyvMemcache(user +":"+ pass +"@"+ server);
|
|
117
|
+
const keyv = new Keyv({ store: memcache});
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Using Google Cloud
|
|
122
|
+
|
|
123
|
+
1. Go to https://cloud.google.com/ and sign up.
|
|
124
|
+
2. Go to the memcached configuration page in the google cloud console by navigating to Memorystore > Memcached.
|
|
125
|
+
3. On the memcached page (Eg. https://console.cloud.google.com/memorystore/memcached/instances?project=example), Click Create Instance
|
|
126
|
+
4. Fill in all mandatory fields as needed. You will need to set up a private service connection.
|
|
127
|
+
5. To set up a private service connection, click the Set Up Connection button.
|
|
128
|
+
6. Once required fields are complete, click the Create button to create the instance.
|
|
129
|
+
7. Google provides further documentation for connecting to and managing your Memecached instance [here](https://cloud.google.com/memorystore/docs/memcached).
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
import Keyv from 'keyv';
|
|
133
|
+
import KeyvMemcache from '@keyv/memcache';
|
|
134
|
+
|
|
135
|
+
const memcache = new KeyvMemcache("insert the internal google memcached discovery endpoint");
|
|
136
|
+
const keyv = new Keyv({ store: memcache});
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
[MIT © Jared Wray](LISCENCE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
KeyvMemcache: () => KeyvMemcache,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_node_events = __toESM(require("events"), 1);
|
|
38
|
+
var import_memjs = __toESM(require("memjs"), 1);
|
|
39
|
+
var import_serialize = require("@keyv/serialize");
|
|
40
|
+
var KeyvMemcache = class extends import_node_events.default {
|
|
41
|
+
ttlSupport = true;
|
|
42
|
+
namespace;
|
|
43
|
+
client;
|
|
44
|
+
opts;
|
|
45
|
+
constructor(uri, options) {
|
|
46
|
+
super();
|
|
47
|
+
options = {
|
|
48
|
+
...typeof uri === "string" ? { uri } : uri,
|
|
49
|
+
...options
|
|
50
|
+
};
|
|
51
|
+
if (options.uri && options.url === void 0) {
|
|
52
|
+
options.url = options.uri;
|
|
53
|
+
}
|
|
54
|
+
if (uri === void 0) {
|
|
55
|
+
uri = "localhost:11211";
|
|
56
|
+
options.url = options.uri = uri;
|
|
57
|
+
}
|
|
58
|
+
this.opts = options;
|
|
59
|
+
this.client = import_memjs.default.Client.create(uri, options);
|
|
60
|
+
}
|
|
61
|
+
_getNamespace() {
|
|
62
|
+
return `namespace:${this.namespace}`;
|
|
63
|
+
}
|
|
64
|
+
async get(key) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
this.client.get(this.formatKey(key), (error, value) => {
|
|
67
|
+
if (error) {
|
|
68
|
+
this.emit("error", error);
|
|
69
|
+
reject(error);
|
|
70
|
+
} else {
|
|
71
|
+
let value_;
|
|
72
|
+
if (value === null) {
|
|
73
|
+
value_ = {
|
|
74
|
+
value: void 0,
|
|
75
|
+
expires: 0
|
|
76
|
+
};
|
|
77
|
+
} else {
|
|
78
|
+
value_ = this.opts.deserialize ? this.opts.deserialize(value) : (0, import_serialize.defaultDeserialize)(value);
|
|
79
|
+
}
|
|
80
|
+
resolve(value_);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async getMany(keys) {
|
|
86
|
+
const promises = [];
|
|
87
|
+
for (const key of keys) {
|
|
88
|
+
promises.push(this.get(key));
|
|
89
|
+
}
|
|
90
|
+
return Promise.allSettled(promises).then((values) => {
|
|
91
|
+
const data = [];
|
|
92
|
+
for (const value of values) {
|
|
93
|
+
data.push(value.value);
|
|
94
|
+
}
|
|
95
|
+
return data;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
async set(key, value, ttl) {
|
|
99
|
+
const options = {};
|
|
100
|
+
if (ttl !== void 0) {
|
|
101
|
+
options.expires = options.ttl = Math.floor(ttl / 1e3);
|
|
102
|
+
}
|
|
103
|
+
await this.client.set(this.formatKey(key), value, options);
|
|
104
|
+
}
|
|
105
|
+
async delete(key) {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
this.client.delete(this.formatKey(key), (error, success) => {
|
|
108
|
+
if (error) {
|
|
109
|
+
this.emit("error", error);
|
|
110
|
+
reject(error);
|
|
111
|
+
} else {
|
|
112
|
+
resolve(Boolean(success));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async deleteMany(keys) {
|
|
118
|
+
const promises = keys.map(async (key) => this.delete(key));
|
|
119
|
+
const results = await Promise.allSettled(promises);
|
|
120
|
+
return results.every((x) => x.value === true);
|
|
121
|
+
}
|
|
122
|
+
async clear() {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
this.client.flush((error) => {
|
|
125
|
+
if (error) {
|
|
126
|
+
this.emit("error", error);
|
|
127
|
+
reject(error);
|
|
128
|
+
} else {
|
|
129
|
+
resolve(void 0);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
formatKey(key) {
|
|
135
|
+
let result = key;
|
|
136
|
+
if (this.namespace) {
|
|
137
|
+
result = this.namespace.trim() + ":" + key.trim();
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
async has(key) {
|
|
142
|
+
return new Promise((resolve) => {
|
|
143
|
+
this.client.get(this.formatKey(key), (error, value) => {
|
|
144
|
+
if (error) {
|
|
145
|
+
resolve(false);
|
|
146
|
+
} else {
|
|
147
|
+
resolve(value !== null);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var index_default = KeyvMemcache;
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
KeyvMemcache
|
|
157
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import memcache from 'memjs';
|
|
3
|
+
import { KeyvStoreAdapter, StoredData } from 'keyv';
|
|
4
|
+
|
|
5
|
+
type KeyvMemcacheOptions = {
|
|
6
|
+
url?: string;
|
|
7
|
+
expires?: number;
|
|
8
|
+
} & memcache.ClientOptions & Record<string, any>;
|
|
9
|
+
declare class KeyvMemcache extends EventEmitter implements KeyvStoreAdapter {
|
|
10
|
+
ttlSupport: boolean;
|
|
11
|
+
namespace?: string;
|
|
12
|
+
client: memcache.Client;
|
|
13
|
+
opts: KeyvMemcacheOptions;
|
|
14
|
+
constructor(uri?: string, options?: KeyvMemcacheOptions);
|
|
15
|
+
_getNamespace(): string;
|
|
16
|
+
get<Value>(key: string): Promise<StoredData<Value>>;
|
|
17
|
+
getMany<Value>(keys: string[]): Promise<StoredData<Value>[]>;
|
|
18
|
+
set(key: string, value: any, ttl?: number): Promise<void>;
|
|
19
|
+
delete(key: string): Promise<boolean>;
|
|
20
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
21
|
+
clear(): Promise<void>;
|
|
22
|
+
formatKey(key: string): string;
|
|
23
|
+
has(key: string): Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { KeyvMemcache, type KeyvMemcacheOptions, KeyvMemcache as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import memcache from 'memjs';
|
|
3
|
+
import { KeyvStoreAdapter, StoredData } from 'keyv';
|
|
4
|
+
|
|
5
|
+
type KeyvMemcacheOptions = {
|
|
6
|
+
url?: string;
|
|
7
|
+
expires?: number;
|
|
8
|
+
} & memcache.ClientOptions & Record<string, any>;
|
|
9
|
+
declare class KeyvMemcache extends EventEmitter implements KeyvStoreAdapter {
|
|
10
|
+
ttlSupport: boolean;
|
|
11
|
+
namespace?: string;
|
|
12
|
+
client: memcache.Client;
|
|
13
|
+
opts: KeyvMemcacheOptions;
|
|
14
|
+
constructor(uri?: string, options?: KeyvMemcacheOptions);
|
|
15
|
+
_getNamespace(): string;
|
|
16
|
+
get<Value>(key: string): Promise<StoredData<Value>>;
|
|
17
|
+
getMany<Value>(keys: string[]): Promise<StoredData<Value>[]>;
|
|
18
|
+
set(key: string, value: any, ttl?: number): Promise<void>;
|
|
19
|
+
delete(key: string): Promise<boolean>;
|
|
20
|
+
deleteMany(keys: string[]): Promise<boolean>;
|
|
21
|
+
clear(): Promise<void>;
|
|
22
|
+
formatKey(key: string): string;
|
|
23
|
+
has(key: string): Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { KeyvMemcache, type KeyvMemcacheOptions, KeyvMemcache as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import EventEmitter from "events";
|
|
3
|
+
import memcache from "memjs";
|
|
4
|
+
import { defaultDeserialize } from "@keyv/serialize";
|
|
5
|
+
var KeyvMemcache = class extends EventEmitter {
|
|
6
|
+
ttlSupport = true;
|
|
7
|
+
namespace;
|
|
8
|
+
client;
|
|
9
|
+
opts;
|
|
10
|
+
constructor(uri, options) {
|
|
11
|
+
super();
|
|
12
|
+
options = {
|
|
13
|
+
...typeof uri === "string" ? { uri } : uri,
|
|
14
|
+
...options
|
|
15
|
+
};
|
|
16
|
+
if (options.uri && options.url === void 0) {
|
|
17
|
+
options.url = options.uri;
|
|
18
|
+
}
|
|
19
|
+
if (uri === void 0) {
|
|
20
|
+
uri = "localhost:11211";
|
|
21
|
+
options.url = options.uri = uri;
|
|
22
|
+
}
|
|
23
|
+
this.opts = options;
|
|
24
|
+
this.client = memcache.Client.create(uri, options);
|
|
25
|
+
}
|
|
26
|
+
_getNamespace() {
|
|
27
|
+
return `namespace:${this.namespace}`;
|
|
28
|
+
}
|
|
29
|
+
async get(key) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
this.client.get(this.formatKey(key), (error, value) => {
|
|
32
|
+
if (error) {
|
|
33
|
+
this.emit("error", error);
|
|
34
|
+
reject(error);
|
|
35
|
+
} else {
|
|
36
|
+
let value_;
|
|
37
|
+
if (value === null) {
|
|
38
|
+
value_ = {
|
|
39
|
+
value: void 0,
|
|
40
|
+
expires: 0
|
|
41
|
+
};
|
|
42
|
+
} else {
|
|
43
|
+
value_ = this.opts.deserialize ? this.opts.deserialize(value) : defaultDeserialize(value);
|
|
44
|
+
}
|
|
45
|
+
resolve(value_);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async getMany(keys) {
|
|
51
|
+
const promises = [];
|
|
52
|
+
for (const key of keys) {
|
|
53
|
+
promises.push(this.get(key));
|
|
54
|
+
}
|
|
55
|
+
return Promise.allSettled(promises).then((values) => {
|
|
56
|
+
const data = [];
|
|
57
|
+
for (const value of values) {
|
|
58
|
+
data.push(value.value);
|
|
59
|
+
}
|
|
60
|
+
return data;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async set(key, value, ttl) {
|
|
64
|
+
const options = {};
|
|
65
|
+
if (ttl !== void 0) {
|
|
66
|
+
options.expires = options.ttl = Math.floor(ttl / 1e3);
|
|
67
|
+
}
|
|
68
|
+
await this.client.set(this.formatKey(key), value, options);
|
|
69
|
+
}
|
|
70
|
+
async delete(key) {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
this.client.delete(this.formatKey(key), (error, success) => {
|
|
73
|
+
if (error) {
|
|
74
|
+
this.emit("error", error);
|
|
75
|
+
reject(error);
|
|
76
|
+
} else {
|
|
77
|
+
resolve(Boolean(success));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async deleteMany(keys) {
|
|
83
|
+
const promises = keys.map(async (key) => this.delete(key));
|
|
84
|
+
const results = await Promise.allSettled(promises);
|
|
85
|
+
return results.every((x) => x.value === true);
|
|
86
|
+
}
|
|
87
|
+
async clear() {
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
this.client.flush((error) => {
|
|
90
|
+
if (error) {
|
|
91
|
+
this.emit("error", error);
|
|
92
|
+
reject(error);
|
|
93
|
+
} else {
|
|
94
|
+
resolve(void 0);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
formatKey(key) {
|
|
100
|
+
let result = key;
|
|
101
|
+
if (this.namespace) {
|
|
102
|
+
result = this.namespace.trim() + ":" + key.trim();
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
async has(key) {
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
this.client.get(this.formatKey(key), (error, value) => {
|
|
109
|
+
if (error) {
|
|
110
|
+
resolve(false);
|
|
111
|
+
} else {
|
|
112
|
+
resolve(value !== null);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var index_default = KeyvMemcache;
|
|
119
|
+
export {
|
|
120
|
+
KeyvMemcache,
|
|
121
|
+
index_default as default
|
|
122
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,88 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/keyv-memcache",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.2-beta.0",
|
|
4
|
+
"description": "Memcache storage adapter for Keyv",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"xo": {
|
|
16
|
+
"rules": {
|
|
17
|
+
"import/no-named-as-default": "off",
|
|
18
|
+
"unicorn/prefer-module": "off",
|
|
19
|
+
"unicorn/prefer-event-target": "off",
|
|
20
|
+
"unicorn/no-array-reduce": "off",
|
|
21
|
+
"n/prefer-global/process": "off",
|
|
22
|
+
"node/prefer-global/process": "off",
|
|
23
|
+
"unicorn/prefer-object-from-entries": "off",
|
|
24
|
+
"unicorn/prefer-node-protocol": "off",
|
|
25
|
+
"@typescript-eslint/consistent-type-imports": "off",
|
|
26
|
+
"@typescript-eslint/consistent-type-definitions": "off",
|
|
27
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
28
|
+
"import/extensions": "off",
|
|
29
|
+
"no-promise-executor-return": "off",
|
|
30
|
+
"import/no-extraneous-dependencies": "off"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
36
|
+
"directory": "ports/@keyv/memcache/2.0.2"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"memcache",
|
|
40
|
+
"keyv",
|
|
41
|
+
"storage",
|
|
42
|
+
"adapter",
|
|
43
|
+
"key",
|
|
44
|
+
"value",
|
|
45
|
+
"store",
|
|
46
|
+
"cache",
|
|
47
|
+
"ttl"
|
|
48
|
+
],
|
|
49
|
+
"author": "Jared Wray <me@jaredwray.com> (https://jaredwray.com)",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/jaredwray/keyv",
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"buffer": "^6.0.3",
|
|
57
|
+
"memjs": "^1.3.2",
|
|
58
|
+
"@keyv/serialize": "^1.0.3"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"keyv": "^5.3.4"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/memjs": "^1.3.3",
|
|
65
|
+
"@vitest/coverage-v8": "^3.2.3",
|
|
66
|
+
"rimraf": "^6.0.1",
|
|
67
|
+
"tsd": "^0.32.0",
|
|
68
|
+
"tsup": "^8.5.0",
|
|
69
|
+
"typescript": "^5.8.3",
|
|
70
|
+
"@ohos-ports/vitest": "^5.0.1-beta.0",
|
|
71
|
+
"xo": "^1.1.0",
|
|
72
|
+
"@keyv/compress-gzip": "^2.0.3",
|
|
73
|
+
"@keyv/test-suite": "^2.0.7"
|
|
74
|
+
},
|
|
75
|
+
"tsd": {
|
|
76
|
+
"directory": "test"
|
|
77
|
+
},
|
|
78
|
+
"files": [
|
|
79
|
+
"dist",
|
|
80
|
+
"LICENSE"
|
|
81
|
+
],
|
|
82
|
+
"scripts": {
|
|
83
|
+
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
84
|
+
"test": "xo --fix && vitest run --coverage",
|
|
85
|
+
"test:ci": "xo && vitest --run --sequence.setupFiles=list",
|
|
86
|
+
"clean": "rimraf ./node_modules ./coverage ./dist"
|
|
87
|
+
}
|
|
88
|
+
}
|