Memcache Plus
raw JSON → 0.3.1 verified Fri May 01 auth: no javascript
memcache-plus is a Node.js memcache client with native Promise support, Elasticache auto-discovery, command buffering, and built-in compression. Current stable version is 0.3.1. Released irregularly. It differentiates from other memcache clients (like memcached) by providing a clean Promise-based API, automatic Elasticache cluster detection, and a flag to disable caching for testing. Supports both callbacks and Promises, and allows starting commands before connection (buffering).
Common errors
error Error: connect ECONNREFUSED 127.0.0.1:11211 ↓
cause Memcached server is not running or port is wrong.
fix
Start memcached: memcached -d start or check the host/port.
error TypeError: client.get is not a function ↓
cause Using the client before calling connect() or mixing import styles.
fix
Await client.connect() first, or use the ESM import: import MemcachePlus from 'memcache-plus'.
error Cannot find module 'memcache-plus' ↓
cause Package not installed or incorrectly installed.
fix
Run: npm install memcache-plus
Warnings
breaking The connect() method must be awaited; otherwise commands may fail silently. ↓
fix Always await client.connect() before issuing commands.
deprecated Callback-based API is deprecated in favor of Promises. ↓
fix Use async/await or .then() instead of callbacks.
gotcha The set() method expects a TTL in seconds (not milliseconds) – common mistake. ↓
fix Pass TTL in seconds, e.g., 3600 for 1 hour.
gotcha Elasticache auto-discovery expects a configuration endpoint, not a node list. ↓
fix For Elasticache, pass the configuration endpoint URL as the host string.
Install
npm install memcache-plus yarn add memcache-plus pnpm add memcache-plus Imports
- MemcachePlus wrong
import { MemcachePlus } from 'memcache-plus'correctimport MemcachePlus from 'memcache-plus' - Client constructor wrong
const client = new require('memcache-plus')(hosts);correctconst MemcachePlus = require('memcache-plus'); const client = new MemcachePlus(hosts); - MemoryStore wrong
import MemoryStore from 'memcache-plus'correctimport MemcachePlus from 'memcache-plus'
Quickstart
const MemcachePlus = require('memcache-plus');
async function main() {
const client = new MemcachePlus(['127.0.0.1:11211']);
// Wait for connection
await client.connect();
// Set a value
await client.set('key', 'value', 3600);
// Get a value
const val = await client.get('key');
console.log(val); // 'value'
// Delete
await client.delete('key');
// Disconnect
client.disconnect();
}
main().catch(console.error);