Comparing version 0.2.2 to 0.2.3
{ | ||
"name": "iomem", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Memcached client with binary protocol support and multi keys commands", | ||
@@ -8,9 +8,8 @@ "keywords": [ | ||
"memcache", | ||
"memcached", | ||
"memcached-client", | ||
"binary-protocol", | ||
"memcached-binary", | ||
"nosql", | ||
"elasticache", | ||
"client", | ||
"cluster", | ||
"binary", | ||
"protocol", | ||
"multi", | ||
@@ -21,6 +20,6 @@ "multi-get", | ||
"failover", | ||
"hashring", | ||
"async", | ||
"promise" | ||
"hashring" | ||
], | ||
"homepage": "https://github.com/alexzel/iomem#readme", | ||
"bugs": "https://github.com/alexzel/iomem/issues", | ||
"repository": "https://github.com/alexzel/iomem.git", | ||
@@ -27,0 +26,0 @@ "author": "Alex Zelensky", |
@@ -14,3 +14,3 @@ # `iomem` | ||
- Implement commands: append, prepend, gat, touch, stat, noop, version | ||
- Implement commands: gat, touch, stat | ||
- Reconsider API | ||
@@ -151,7 +151,7 @@ - Cleanup and improve | ||
`gets(key): {key: cas}|null` - get a `key => cas` object for a single key. | ||
`gets(key): cas|null` - get cas for a single key. | ||
`gets([key1, ...]): {key: cas, ...}` - get a `key => cas` object for multiple keys. | ||
`getsv(key): {key: {value, cas}}|null` - get a `key => { value, cas }` object for a single key. | ||
`getsv(key): {value, cas}|null` - get cas for a single key. | ||
@@ -232,3 +232,3 @@ `getsv([key1, ...]): {key: {value, cas}}, ...}` - get a `key => { value, cas }` object for multiple keys. | ||
#### FLUSH | ||
#### FLUSH, QUIT, NOOP | ||
@@ -239,2 +239,40 @@ `flush()` - flush cached items. | ||
`quit()` - closes connection that query hits (either existing or a new one). Useless in multi-connection and multi-server environment. | ||
`noop()` - sends empty packet and returns true on success, may be useful for pinging. | ||
#### APPEND AND PREPEND | ||
Append and prepend commands either append or prepend a string value to the existing value stored by a key. | ||
##### Append methods | ||
`append(key, value): true|false` - append value to a stored value | ||
`append([key1, ...], value): true|false` - append value to a stored value for multiple keys | ||
`appends(key, value): cas|null` - append value and return new cas. | ||
`appends([key1, ...], value): [cas1, ...]` - append value to multiple keys and return cas array. | ||
`appendk({key: value, ...}): true|false` - append by `key => value` pairs. | ||
`appendks({key: value, ...}): [cas1, ...]` - append by `key => value` pairs and return cas array. | ||
##### Prepend methods | ||
`prepend(key, value): true|false` - prepend value to a stored value | ||
`prepend([key1, ...], value): true|false` - prepend value to a stored value for multiple keys | ||
`prepends(key, value): cas|null` - prepend value and return new cas. | ||
`prepends([key1, ...], value): [cas1, ...]` - prepend value to multiple keys and return cas array. | ||
`prependk({key: value, ...}): true|false` - prepend by `key => value` object. | ||
`prependks({key: value, ...}): [cas1, ...]` - prepend by `key => value` object and return cas array. | ||
### Streams | ||
@@ -241,0 +279,0 @@ |
@@ -80,2 +80,8 @@ 'use strict' | ||
static quit () { | ||
const args = ['quit'] | ||
args.silent = true | ||
return args | ||
} | ||
static flush (expiry) { | ||
@@ -85,2 +91,50 @@ return ['flush', expiry] | ||
static noop () { | ||
return ['noop'] | ||
} | ||
static version () { | ||
return ['version'] | ||
} | ||
static append (key, value) { | ||
return ['append', key, value] | ||
} | ||
static appends (key, value) { | ||
const args = ['appends', key, value] | ||
args.loud = true | ||
return args | ||
} | ||
static appendk (key) { | ||
return ['append', key] | ||
} | ||
static appendks (key) { | ||
const args = ['appends', key] | ||
args.loud = true | ||
return args | ||
} | ||
static prepend (key, value) { | ||
return ['prepend', key, value] | ||
} | ||
static prepends (key, value) { | ||
const args = ['prepends', key, value] | ||
args.loud = true | ||
return args | ||
} | ||
static prependk (key) { | ||
return ['prepend', key] | ||
} | ||
static prependks (key) { | ||
const args = ['prepends', key] | ||
args.loud = true | ||
return args | ||
} | ||
get (key) { | ||
@@ -142,2 +196,6 @@ return this._net.query(Client.get(key)) | ||
quit () { | ||
return this._net.query(Client.quit()) | ||
} | ||
flush (expiry) { | ||
@@ -147,2 +205,42 @@ return this._net.query(Client.flush(expiry)) | ||
noop () { | ||
return this._net.query(Client.noop()) | ||
} | ||
version () { | ||
return this._net.query(Client.version()) | ||
} | ||
append (key, value) { | ||
return this._net.query(Client.append(key, value)) | ||
} | ||
appends (key, value) { | ||
return this._net.query(Client.appends(key, value)) | ||
} | ||
appendk (key) { | ||
return this._net.query(Client.appendk(key)) | ||
} | ||
appendks (key) { | ||
return this._net.query(Client.appendks(key)) | ||
} | ||
prepend (key, value) { | ||
return this._net.query(Client.prepend(key, value)) | ||
} | ||
prepends (key, value) { | ||
return this._net.query(Client.prepends(key, value)) | ||
} | ||
prependk (key) { | ||
return this._net.query(Client.prependk(key)) | ||
} | ||
prependks (key) { | ||
return this._net.query(Client.prependks(key)) | ||
} | ||
stream () { | ||
@@ -149,0 +247,0 @@ return this._net.query() |
@@ -11,3 +11,3 @@ 'use strict' | ||
const { buildPacket, parsePacket, parseHeader, HEADER_LENGTH, REQUEST_MAGIC, RESPONSE_MAGIC } = require('./packet') | ||
const { STATUS_MESSAGE_MAP, STATUS_MESSAGE_UNKOWN, STATUS_SUCCESS, STATUS_NOT_FOUND, STATUS_EXISTS } = require('./statuses') | ||
const { STATUS_MESSAGE_MAP, STATUS_MESSAGE_UNKOWN, STATUS_SUCCESS, STATUS_NOT_FOUND, STATUS_NOT_STORED, STATUS_EXISTS } = require('./statuses') | ||
const { getKeyFlags } = require('./keys') | ||
@@ -77,3 +77,3 @@ | ||
: protocol[method](key, ...args, lastOpaque) | ||
if (keyFlags.isMultikey && quietOpcode && keys.size !== ++counter) { | ||
if (keyFlags.isMultikey && quietOpcode && !data.loud && keys.size !== ++counter) { | ||
params[0] = quietOpcode | ||
@@ -133,3 +133,3 @@ } | ||
keysStat.exists++ | ||
} else if (packet[5] === STATUS_NOT_FOUND) { // not found | ||
} else if (packet[5] === STATUS_NOT_FOUND || packet[5] === STATUS_NOT_STORED) { // not found | ||
keysStat.misses++ | ||
@@ -155,3 +155,3 @@ } else { | ||
pass.on('end', () => { | ||
done(new Error('iomem: socket closed unexpectedly')) | ||
done(data.silent ? null : new Error('iomem: socket closed unexpectedly')) | ||
}) | ||
@@ -158,0 +158,0 @@ |
@@ -10,4 +10,4 @@ 'use strict' | ||
// add, set, replace mutations | ||
const mutation = (opcode, key, value, expiry = 0, cas = DEFAULT_CAS, opaque = DEFAULT_OPAQUE) => { | ||
// add, set, replace | ||
const setter = (opcode, key, value, expiry = 0, cas = DEFAULT_CAS, opaque = DEFAULT_OPAQUE) => { | ||
const [buffer, flags] = serialize(value) | ||
@@ -20,2 +20,7 @@ const extras = Buffer.alloc(8) | ||
const midifier = (opcode, key, value, opaque = DEFAULT_OPAQUE) => { | ||
const [buffer] = serialize(value) | ||
return [opcode, key, buffer, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque] | ||
} | ||
// increment and decrement | ||
@@ -67,3 +72,3 @@ const counter = (opcode, key, initial, delta, expiry = 0, opaque = DEFAULT_OPAQUE) => { | ||
(packet, buffer) => (buffer[packet[2]] = packet[6]), | ||
(keyFlags, buffer, keysStat) => keyFlags.isArray ? buffer : keysStat.misses ? null : buffer, | ||
(keyFlags, buffer, keysStat) => keyFlags.isArray ? buffer : keysStat.misses ? null : buffer[Object.keys(buffer)[0]], | ||
true | ||
@@ -76,3 +81,3 @@ ) | ||
(packet, buffer) => (buffer[packet[2]] = { value: deserialize(packet[3], packet[4].readUInt32BE(0)), cas: packet[6] }), | ||
(keyFlags, buffer, keysStat) => keyFlags.isArray ? buffer : keysStat.misses ? null : buffer, | ||
(keyFlags, buffer, keysStat) => keyFlags.isArray ? buffer : keysStat.misses ? null : buffer[Object.keys(buffer)[0]], | ||
true | ||
@@ -83,3 +88,3 @@ ) | ||
const set = createMethod( | ||
(key, value, expiry, opaque) => mutation(OPCODES.set, key, value, expiry, DEFAULT_CAS, opaque), | ||
(key, value, expiry, opaque) => setter(OPCODES.set, key, value, expiry, DEFAULT_CAS, opaque), | ||
null, | ||
@@ -90,3 +95,3 @@ (keyFlags, buffer, keysStat) => !keysStat.misses && !keysStat.exists | ||
const add = createMethod( | ||
(key, value, expiry, opaque) => mutation(OPCODES.add, key, value, expiry, DEFAULT_CAS, opaque), | ||
(key, value, expiry, opaque) => setter(OPCODES.add, key, value, expiry, DEFAULT_CAS, opaque), | ||
null, | ||
@@ -97,3 +102,3 @@ (keyFlags, buffer, keysStat) => !keysStat.misses && !keysStat.exists | ||
const replace = createMethod( | ||
(key, value, expiry, opaque) => mutation(OPCODES.replace, key, value, expiry, DEFAULT_CAS, opaque), | ||
(key, value, expiry, opaque) => setter(OPCODES.replace, key, value, expiry, DEFAULT_CAS, opaque), | ||
null, | ||
@@ -104,3 +109,3 @@ (keyFlags, buffer, keysStat) => !keysStat.misses && !keysStat.exists | ||
const cas = createMethod( | ||
(key, value, expiry, cas, opaque) => mutation(OPCODES.set, key, value, expiry, cas, opaque), | ||
(key, value, expiry, cas, opaque) => setter(OPCODES.set, key, value, expiry, cas, opaque), | ||
null, | ||
@@ -128,4 +133,4 @@ (keyFlags, buffer, keysStat) => !keysStat.misses && !keysStat.exists | ||
const quit = (opaque) => | ||
[OPCODES.quit, DEFAULT_KEY, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque] | ||
const quit = () => | ||
[OPCODES.quit, DEFAULT_KEY, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, DEFAULT_OPAQUE] | ||
@@ -135,8 +140,38 @@ const flush = (expiry, opaque) => | ||
const append = (key, value, opaque) => | ||
[OPCODES.append, key, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque] | ||
const noop = createMethod( | ||
(_, opaque) => [OPCODES.noop, DEFAULT_KEY, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque], | ||
null, | ||
() => true | ||
) | ||
const prepend = (key, value, opaque) => | ||
[OPCODES.prepend, key, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque] | ||
const version = createMethod( | ||
(_, opaque) => [OPCODES.version, DEFAULT_KEY, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque], | ||
(packet, buffer) => buffer.push(packet[3].toString()), | ||
(keyFlags, buffer) => (buffer[0] || null) | ||
) | ||
const append = createMethod( | ||
(key, value, opaque) => midifier(OPCODES.append, key, value, opaque), | ||
null, | ||
(keyFlags, buffer, keysStat) => !keysStat.misses && !keysStat.exists | ||
) | ||
const appends = createMethod( | ||
(key, value, opaque) => midifier(OPCODES.append, key, value, opaque), | ||
(packet, buffer) => buffer.push(packet[6]), | ||
(keyFlags, buffer, keysStat) => keyFlags.isMultikey ? buffer : keysStat.misses ? null : buffer[0] | ||
) | ||
const prepend = createMethod( | ||
(key, value, opaque) => midifier(OPCODES.prepend, key, value, opaque), | ||
null, | ||
(keyFlags, buffer, keysStat) => !keysStat.misses && !keysStat.exists | ||
) | ||
const prepends = createMethod( | ||
(key, value, opaque) => midifier(OPCODES.prepend, key, value, opaque), | ||
(packet, buffer) => buffer.push(packet[6]), | ||
(keyFlags, buffer, keysStat) => keyFlags.isMultikey ? buffer : keysStat.misses ? null : buffer[0] | ||
) | ||
const gat = (key, expiry, opaque) => | ||
@@ -151,8 +186,2 @@ expiring(OPCODES.gat, key, expiry, opaque) | ||
const noop = (opaque) => | ||
[OPCODES.noop, DEFAULT_KEY, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque] | ||
const version = (opaque) => | ||
[OPCODES.version, DEFAULT_KEY, DEFAULT_VALUE, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, opaque] | ||
const saslauth = (key, value) => | ||
@@ -175,10 +204,12 @@ [OPCODES.saslauth, key, value, DEFAULT_EXTRAS, DEFAULT_STATUS, DEFAULT_CAS, DEFAULT_OPAQUE] | ||
flush, | ||
noop, | ||
version, | ||
append, | ||
appends, | ||
prepend, | ||
prepends, | ||
gat, | ||
touch, | ||
stat, | ||
noop, | ||
version, | ||
saslauth | ||
} |
@@ -32,2 +32,3 @@ 'use strict' | ||
const STATUS_NOT_FOUND = 0x0001 | ||
const STATUS_NOT_STORED = 0x0005 | ||
const STATUS_EXISTS = 0x0002 | ||
@@ -40,3 +41,4 @@ | ||
STATUS_NOT_FOUND, | ||
STATUS_NOT_STORED, | ||
STATUS_EXISTS | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
49812
1077
1
373