{"id":18293176,"url":"https://github.com/joshbetz/node-memcached","last_synced_at":"2025-11-29T07:04:38.611Z","repository":{"id":63152488,"uuid":"565592882","full_name":"joshbetz/node-memcached","owner":"joshbetz","description":"A Memcached client for modern Node.js with consistent hashing and connection pooling.","archived":false,"fork":false,"pushed_at":"2024-11-27T21:48:38.000Z","size":202,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T11:34:18.794Z","etag":null,"topics":["memcached","memcached-client","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshbetz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-13T21:57:34.000Z","updated_at":"2024-11-27T21:48:23.000Z","dependencies_parsed_at":"2023-02-08T13:46:26.011Z","dependency_job_id":"1520d41e-9782-4508-9074-17adb59f5d4c","html_url":"https://github.com/joshbetz/node-memcached","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/joshbetz/node-memcached","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbetz%2Fnode-memcached","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbetz%2Fnode-memcached/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbetz%2Fnode-memcached/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbetz%2Fnode-memcached/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshbetz","download_url":"https://codeload.github.com/joshbetz/node-memcached/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshbetz%2Fnode-memcached/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265411574,"owners_count":23760638,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["memcached","memcached-client","nodejs"],"created_at":"2024-11-05T14:23:05.729Z","updated_at":"2025-11-29T07:04:38.554Z","avatar_url":"https://github.com/joshbetz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Memcached [![Node.js CI](https://github.com/joshbetz/node-memcached/actions/workflows/node.js.yml/badge.svg)](https://github.com/joshbetz/node-memcached/actions/workflows/node.js.yml)\n\nThere are three libraries exported from this package.\n\n```typescript\nconst { Memcached, Pool, HashPool } = require( '@joshbetz/memcached' );\n```\n\n## API\n\nThe API for all three libraries is the same. It just depends what kind of connection and failover logic you need.\n\n```typescript\nasync ready()\n```\n\nWait for the connection to be ready.\n\n```typescript\nasync flush()\n```\n\nFlush the Memcached data.\n\n```typescript\nasync set( key, value, ttl ): Boolean\n```\n\nSETs a given key and value for the specified TTL (or no TTL). Returns a Boolean to indicate whether the operation was successful.\n\n```typescript\nasync add( key, value, ttl ): Boolean\n```\n\nADDs a given key and value for the specified TTL (or no TTL) if it doesn't already exist. Returns a Boolean to indicate whether the operation was successful.\n\n```typescript\nasync get( key ): string|Boolean\n```\n\nGETs a given key. Returns `false` if it does not exist.\n\n```typescript\nasync del( key ): Boolean\n```\n\nDELETEs a given key.\n\n```typescript\nasync ping(): Boolean\n```\n\nSends the version command. Returns `true` if the expected response is returned.\n\n```typescript\nasync end()\n```\n\nClose the connection to Memcached.\n\n## Memcached Library\n\nThis is a simple Memcached library that connects to a Memcached server and execute commands.\n\n### Example\n\n```typescript\nconst opts = {\n    prefix: '',\n    socketTimeout: 100,\n};\nconst memcached = new Memcached( 11211, 'localhost', opts );\nawait memcached.ready();\nawait memcached.set( 'key', 'value' );\nconst value = await memcached.get( 'key' );\nawait memcached.end();\n```\n\n### Options\n\n* `prefix` A prefix to apply to all keys. Default: (empty string)\n* `socketTimeout` The timeout to establish a connection. Default: 100.\n\n## Pool Library\n\nThis is a wrapper around our Memcached library that establishes a connection pool.\n\n### Example\n\n```typescript\nconst opts = {\n    // Pool options\n    max: 10,\n    min: 2,\n    acquireTimeoutMillis: 200,\n    destroyTimeoutMillis: 200,\n    maxWaitingClients: 2,\n    idleTimeoutMillis: 30000,\n\n    // Connection options\n    prefix: '',\n    socketTimeout: 100,\n};\nconst memcached = new Pool( 11211, 'localhost', opts );\nawait memcached.set( 'key', 'value' );\nconst value = await memcached.get( 'key' );\nawait memcached.end();\n```\n\n### Options\n\n* `max` The maximum number of connections in the pool. Default: 10.\n* `min` The minimum number of connections in the pool. Default: 2.\n* `acquireTimeoutMillis` The maximum amount of time to wait to create a connection. Default: 200.\n* `destroyTimeoutMillis` The maximum amount of time to wait to destroy a connection. Default: 200.\n* `maxWaitingClients` The maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future cycle of the event loop. Default: 2.\n* `idleTimeoutMillis` The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due to idle time. Default: 30000.\n* `prefix` A prefix to apply to all keys. Default: (empty string)\n* `socketTimeout` The timeout to establish a connection. Default: 100.\n\n## HashPool Library\n\nThis is a wrapper around our Pool library that establishes connection pools to each host and load balances queries across them. It includes automatic failover and reconnecting when hosts experience issues.\n\n### Example\n\n```typescript\nconst opts = {\n    retry: ( retries: number ): number =\u003e {\n        const exp = Math.pow( 2, retries ) * 250;\n\n        // exponential backoff up to 30 seconds\n        return Math.min( exp, 30000 );\n    },\n\n    // Pool options\n    max: 10,\n    min: 2,\n    acquireTimeoutMillis: 200,\n    destroyTimeoutMillis: 200,\n    maxWaitingClients: 2,\n    idleTimeoutMillis: 30000,\n\n    // Connection options\n    prefix: '',\n    socketTimeout: 100,\n};\nconst memcached = new HashPool( [ 'localhost:11211', 'localhost:11311' ], opts );\nawait memcached.set( 'key', 'value' );\nconst value = await memcached.get( 'key' );\nawait memcached.end();\n```\n\n### Options\n\n* `retry` A function that takes the number of retries as a parameter and returns the time before the next retry in milliseconds.\n* `max` The maximum number of connections in the pool. Default: 10.\n* `min` The minimum number of connections in the pool. Default: 2.\n* `acquireTimeoutMillis` The maximum amount of time to wait to create a connection. Default: 200.\n* `destroyTimeoutMillis` The maximum amount of time to wait to destroy a connection. Default: 200.\n* `maxWaitingClients` The maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future cycle of the event loop. Default: 2.\n* `idleTimeoutMillis` The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due to idle time. Default: 30000.\n* `prefix` A prefix to apply to all keys. Default: (empty string)\n* `socketTimeout` The timeout to establish a connection. Default: 100.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshbetz%2Fnode-memcached","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshbetz%2Fnode-memcached","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshbetz%2Fnode-memcached/lists"}