forked from classdojo/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
336 lines (301 loc) · 9.29 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// Type definitions for memcached 2.2
// Project: https://github.com/3rd-Eden/memcached, https://github.com/3rd-eden/node-memcached
// Definitions by: KentarouTakeda <https://github.com/KentarouTakeda>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
import events = require("events");
export = Memcached;
declare class Memcached extends events.EventEmitter {
static config: Memcached.options;
/**
* Connect to a single Memcached server or cluster
* @param location Server locations
* @param options options
*/
constructor(location: Memcached.Location, options?: Memcached.options);
/**
* Touches the given key.
* @param key The key
* @param lifetime After how long should the key expire measured in seconds
*/
touch(key: string, lifetime: number, cb: (this: Memcached.CommandData, err: any) => void): void;
/**
* Get the value for the given key.
* @param key The key
*/
get(key: string, cb: (this: Memcached.CommandData, err: any, data: any) => void): void;
/**
* Get the value and the CAS id.
* @param key The key
*/
gets(
key: string,
cb: (this: Memcached.CommandData, err: any, data: { [key: string]: any; cas: string }) => void,
): void;
/**
* Retrieves a bunch of values from multiple keys.
* @param keys all the keys that needs to be fetched
*/
getMulti(keys: string[], cb: (this: undefined, err: any, data: { [key: string]: any }) => void): void;
/**
* Stores a new value in Memcached.
*
* @param key The key
* @param value Either a buffer, JSON, number or string that you want to store.
*/
set(
key: string,
value: any,
lifetime: number,
cb: (this: Memcached.CommandData, err: any, result: boolean) => void,
): void;
/**
* Replaces the value in memcached.
* @param key The key
* @param value Either a buffer, JSON, number or string that you want to store.
*/
replace(
key: string,
value: any,
lifetime: number,
cb: (this: Memcached.CommandData, err: any, result: boolean) => void,
): void;
/**
* Add the value, only if it's not in memcached already.
* @param key The key
* @param value Either a buffer, JSON, number or string that you want to store.
*/
add(
key: string,
value: any,
lifetime: number,
cb: (this: Memcached.CommandData, err: any, result: boolean) => void,
): void;
/**
* Add the value, only if it matches the given CAS value.
* @param key The key
* @param value Either a buffer, JSON, number or string that you want to store.
*/
cas(
key: string,
value: any,
cas: string,
lifetime: number,
cb: (this: Memcached.CommandData, err: any, result: boolean) => void,
): void;
/**
* Add the given value string to the value of an existing item.
* @param key The key
* @param value Either a buffer, JSON, number or string that you want to store.
*/
append(key: string, value: any, cb: (this: Memcached.CommandData, err: any, result: boolean) => void): void;
/**
* Add the given value string to the value of an existing item.
* @param key The key
* @param value Either a buffer, JSON, number or string that you want to store.
*/
prepend(key: string, value: any, cb: (this: Memcached.CommandData, err: any, result: boolean) => void): void;
/**
* Increment a given key.
* @param key The key
* @param amount The increment
*/
incr(
key: string,
amount: number,
cb: (this: Memcached.CommandData, err: any, result: boolean | number) => void,
): void;
/**
* Increment a given key, or adds it with the value 1
* @param key The key
* @param amount The increment
*/
addincr(
key: string,
amount: number,
cb: (this: Memcached.CommandData, err: any, result: boolean | number) => void,
): void;
/**
* Decrement a given key.
* @param key The key
* @param amount The decrement
*/
decr(
key: string,
amount: number,
cb: (this: Memcached.CommandData, err: any, result: boolean | number) => void,
): void;
/**
* Remove the key from memcached.
* @param key The key
*/
del(key: string, cb: (this: Memcached.CommandData, err: any, result: boolean) => void): void;
/**
* Retrieves the version number of your server.
*/
version(cb: (err: any, version: Memcached.VersionData[]) => void): void;
/**
* Retrieves your stats settings.
*/
settings(cb: (err: any, settings: Memcached.StatusData[]) => void): void;
/**
* Retrieves stats from your memcached server.
*/
stats(cb: (err: any, stats: Memcached.StatusData[]) => void): void;
/**
* Retrieves stats slabs information.
*/
slabs(cb: (err: any, stats: Memcached.StatusData[]) => void): void;
/**
* Retrieves stats items information.
*/
items(cb: (err: any, stats: Memcached.StatusData[]) => void): void;
/**
* Inspect cache, see examples for a detailed explanation.
*/
cachedump(
server: string,
slabid: number,
number: number,
cb: (err: any, cachedump: Memcached.CacheDumpData | Memcached.CacheDumpData[]) => void,
): void;
/**
* Flushes the memcached server.
*/
flush(cb: (this: undefined, err: any, results: boolean[]) => void): void;
/**
* Register event listener
*/
on(event: Memcached.EventNames, cb: (err: Memcached.IssueData) => void): this;
/**
* Closes all active memcached connections.
*/
end(): void;
}
declare namespace Memcached {
interface IssueData {
server: string;
tokens: [string, string];
messages: string[];
failures?: number | undefined;
totalFailures?: number | undefined;
totalReconnectsAttempted?: number | undefined;
totalReconnectsSuccess?: number | undefined;
totalReconnectsFailed?: number | undefined;
totalDownTime?: number | undefined;
}
interface CommandData {
start: number;
execution: number;
callback(...args: any[]): any;
type: string;
command: string;
validate: Array<[string, (...args: any[]) => any]>;
cas?: string | undefined;
redundancyEnabled?: boolean | undefined;
key?: string | undefined;
value?: any;
lifetime?: number | undefined;
}
interface StatusData {
server?: string | undefined;
[key: string]: string | boolean | number | undefined;
}
interface VersionData extends StatusData {
version: string;
major: string;
minor: string;
bugfix: string;
}
interface CacheDumpData {
key: string;
b: number;
s: number;
}
/**
* <ul>
* <li><b>issue</b> a issue occurred on a server, we are going to attempt a retry next.</li>
* <li><b>failure</b> a server has been marked as failure or dead.</li>
* <li><b>reconnecting</b> we are going to attempt to reconnect the to the failed server.</li>
* <li><b>reconnect</b> successfully reconnected to the memcached server.</li>
* <li><b>remove</b> removing the server from our consistent hashing.</li>
* </ul>
*/
type EventNames = "issue" | "failure" | "reconnecting" | "reconnect" | "remove";
/**
* Declaration for single server or Memcached cluster location
*
* to connect to a single server use
* "127.0.0.1:11211"
*
* to connect to a cluster of Memcached servers use
* ["127.0.0.1:11211","127.0.0.1:11212"]
*
* to connect to servers with weight use
* {"127.0.0.1:11211": 1,"127.0.0.1:11212": 2}
*/
type Location = string | string[] | { [server: string]: number };
interface options {
/**
* 250, the maximum key size allowed.
*/
maxKeySize?: number | undefined;
/**
* 2592000, the maximum expiration time of keys (in seconds).
*/
maxExpiration?: number | undefined;
/**
* 1048576, the maximum size of a value.
*/
maxValue?: number | undefined;
/**
* 10, the maximum size of the connection pool.
*/
poolSize?: number | undefined;
/**
* md5, the hashing algorithm used to generate the hashRing values.
*/
algorithm?: string | undefined;
/**
* 18000000, the time between reconnection attempts (in milliseconds).
*/
reconnect?: number | undefined;
/**
* 5000, the time after which Memcached sends a connection timeout (in milliseconds).
*/
timeout?: number | undefined;
/**
* 5, the number of socket allocation retries per request.
*/
retries?: number | undefined;
/**
* 5, the number of failed-attempts to a server before it is regarded as 'dead'.
*/
failures?: number | undefined;
/**
* 30000, the time between a server failure and an attempt to set it up back in service.
*/
retry?: number | undefined;
/**
* false, if true, authorizes the automatic removal of dead servers from the pool.
*/
remove?: boolean | undefined;
/**
* undefined, an array of server_locations to replace servers that fail and that are removed from the consistent hashing scheme.
*/
failOverServers?: string | string[] | undefined;
/**
* true, whether to use md5 as hashing scheme when keys exceed maxKeySize.
*/
keyCompression?: boolean | undefined;
/**
* 5000, the idle timeout for the connections.
*/
idle?: number | undefined;
/**
* '', sentinel to prepend to all memcache keys for namespacing the entries.
*/
namespace?: string | undefined;
}
}