{"library":"memcache-client","title":"Node.js Memcached Client","description":"memcache-client is a high-performance Node.js client designed for interacting with Memcached servers, focusing on efficient ASCII protocol parsing through direct Node.js Buffer APIs. Originally developed and heavily used at WalmartLabs for powering the walmart.com e-commerce platform, it offers robust features crucial for large-scale applications. These include optional data compression, automatic reconnection on network errors, support for arbitrary Memcached commands, and the ability to store various data types like Buffer, string, numeric, and JSON. The library provides a flexible API supporting both traditional Node.js callbacks and modern Promise-based operations, alongside features like fire-and-forget requests, multiple connections, and TLS support. It is currently at version 1.0.5 and appears to be in a maintenance or stable release state, with a focus on reliability and performance in demanding environments.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install memcache-client"],"cli":null},"imports":["import { MemcacheClient } from 'memcache-client';","import { MultiRetrievalResponse } from 'memcache-client';","client.set('key', 'data').then((r) => console.log(r));"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { MemcacheClient, MultiRetrievalResponse } from 'memcache-client';\nimport assert from 'node:assert';\n\nconst server = 'localhost:11211';\n\n// Create a client with default settings (maxConnections = 1)\nconst client = new MemcacheClient({ server });\n\nasync function runMemcacheExample() {\n  try {\n    // Set a key-value pair using Promises\n    const setResult = await client.set('myKey', 'myValue');\n    assert.deepEqual(setResult, ['STORED']);\n    console.log('Set \"myKey\":', setResult);\n\n    // Get the value of 'myKey' using Promises, with type assertion\n    const getData = await client.get<string>('myKey');\n    assert.equal(getData?.value, 'myValue');\n    console.log('Got \"myKey\":', getData?.value);\n\n    // Set multiple keys concurrently\n    await Promise.all([\n      client.set('key1', 'data1'),\n      client.set('key2', 'data2')\n    ]);\n    console.log('Set \"key1\" and \"key2\".');\n\n    // Get multiple keys with correct TypeScript typing\n    const multiResults = await client.get<MultiRetrievalResponse<string>>(['key1', 'key2']);\n    assert.equal(multiResults['key1'].value, 'data1');\n    assert.equal(multiResults['key2'].value, 'data2');\n    console.log('Got multiple keys:', multiResults);\n\n    // Example with callback for 'delete' (optional pattern)\n    client.delete('myKey', (err, result) => {\n      if (err) {\n        console.error('Delete error:', err);\n      } else {\n        assert.deepEqual(result, ['DELETED']);\n        console.log('Deleted \"myKey\":', result);\n      }\n    });\n  } catch (error) {\n    console.error('An error occurred:', error);\n  } finally {\n    // It's good practice to close connections if not needed anymore, though auto-reconnect handles many cases\n    // client.disconnect(); // (Assuming a disconnect method exists or client handles it internally)\n  }\n}\n\nrunMemcacheExample();","lang":"typescript","description":"This quickstart demonstrates creating a MemcacheClient, setting and retrieving single keys using Promises, concurrently setting multiple keys, and performing a typed multi-key retrieval. It also shows an example of using a callback for deletion.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}