{"id":28159587,"url":"https://github.com/ofek29/fastify-valkey-glide-dev","last_synced_at":"2026-04-29T13:36:05.063Z","repository":{"id":292000102,"uuid":"978012845","full_name":"ofek29/fastify-valkey-glide-dev","owner":"ofek29","description":"Plugin to share Valkey connection across Fastify","archived":false,"fork":false,"pushed_at":"2025-05-15T09:21:50.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-15T09:24:49.052Z","etag":null,"topics":["caching","fastify","fastify-plugin","valkey","valkey-glide"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@ofek.a/fastify-valkey-glide","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ofek29.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-05-05T10:35:28.000Z","updated_at":"2025-05-15T09:00:16.000Z","dependencies_parsed_at":"2025-05-07T16:48:12.559Z","dependency_job_id":null,"html_url":"https://github.com/ofek29/fastify-valkey-glide-dev","commit_stats":null,"previous_names":["ofek29/fastify-valkey-glide"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek29%2Ffastify-valkey-glide-dev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek29%2Ffastify-valkey-glide-dev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek29%2Ffastify-valkey-glide-dev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ofek29%2Ffastify-valkey-glide-dev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ofek29","download_url":"https://codeload.github.com/ofek29/fastify-valkey-glide-dev/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319720,"owners_count":22051075,"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":["caching","fastify","fastify-plugin","valkey","valkey-glide"],"created_at":"2025-05-15T10:11:09.979Z","updated_at":"2026-04-29T13:36:00.037Z","avatar_url":"https://github.com/ofek29.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @ofek.a/fastify-valkey-glide\n\nFastify Valkey connection plugin, with this you can share the same Valkey connection in every part of your server.\n\nUsing [`@valkey/valkey-glide`](https://github.com/valkey-io/valkey-glide) client under the hood.\nValkey Glide is an open-source Valkey client library. it is one of the official client libraries for Valkey, and it supports all Valkey commands.\n\n### Compatibility\n| Plugin version | Fastify version |\n| ---------------|-----------------|\n|      `1.x`     |      `^5.x`     |\n\nFor Valkey and Redis DB compatibility look [here](https://github.com/valkey-io/valkey-glide?tab=readme-ov-file#supported-engine-versions)\n\n## Usage\n\nAdd it to your project with `register` and you are done!\n\n### Create a new Valkey Client\n\nThe ``options`` that you pass to `register` will be passed to the Valkey client.\n\n```js\nimport Fastify from 'fastify'\nimport fastifyValkey from '@ofek.a/fastify-valkey-glide'\n\nconst fastify = Fastify()\n\n// create by specifying address\nfastify.register(fastifyValkey, {\n  addresses: [{ host: '127.0.0.1' }]\n})\n\n// OR with more options\nfastify.register(fastifyValkey, {\n  addresses: [{ host: '127.0.0.1', port: 6379 }],\n  credentials: {username: \"user1\", password: \"password\"},\n  useTLS: true\n})\n```\n\n### Accessing the Valkey Client\n\nOnce you have registered your plugin, you can access the Valkey client via `fastify.valkey`.\n\nThe client is automatically closed when the fastify instance is closed.\n\n```js\nimport Fastify from 'fastify'\nimport fastifyValkey from '@ofek.a/fastify-valkey-glide'\n\nconst fastify = Fastify({ logger: true })\n\nfastify.register(fastifyValkey, {\n  addresses: [{ host: '127.0.0.1', port: 6379 }],\n})\n\nfastify.post('/foo', (request, reply) =\u003e {\n  fastify.valkey.set(request.body.key, request.body.value, (err) =\u003e {\n    reply.send(err || { status: 'ok' })\n  })\n})\n\nfastify.get('/foo', (request, reply) =\u003e {\n  fastify.valkey.get(request.query.key, (err, val) =\u003e {\n    reply.send(err || val)\n  })\n})\n\ntry {\n  await fastify.listen({ port: 3000 })\n  console.log(`server listening on ${fastify.server.address().port}`)\n} catch (err) {\n  fastify.log.error(err)\n  process.exit(1)\n}\n```\n\n### Using an existing Valkey client\n\nYou may also supply an existing *Valkey* client instance by passing an options\nobject with the `client` property set to the instance. In this case,\nthe client is not automatically closed when the Fastify instance is\nclosed.\n\n```js\nimport Fastify from 'fastify'\nimport fastifyValkey from '@ofek.a/fastify-valkey-glide'\nimport { GlideClient } from '@valkey/valkey-glide'\n\nconst fastify = Fastify()\n\nconst client = await GlideClient.createClient({\n  addresses: [{ host: 'localhost', port: 6379 }]\n})\n\nfastify.register(fastifyValkey, { client })\n```\n\nYou can also supply a *Valkey Cluster* instance to the client:\n\n```js\nimport Fastify from 'fastify'\nimport fastifyValkey from '@ofek.a/fastify-valkey-glide'\nimport { GlideClusterClient } from '@valkey/valkey-glide'\n\nconst fastify = Fastify()\n\nconst client = await GlideClusterClient.createClient({\n  addresses: [{ host: '127.0.0.1', port: 6379 }]\n})\n\nfastify.register(fastifyValkey, { client })\n```\n\nNote: by default, *@fastify/valkey-glide* will **not** automatically close the client\nconnection when the Fastify server shuts down.\n\nTo automatically close the client connection, set clientClose to true.\n\n```js\nfastify.register(fastifyValkey, { \n    client, \n    closeClient: true })\n```\n\n## Registering multiple Valkey client instances\n\nBy using the `namespace` option you can register multiple Valkey client instances.\n\n```js\nimport Fastify from 'fastify'\nimport fastifyValkey from '@ofek.a/fastify-valkey-glide'\nimport { GlideClient } from '@valkey/valkey-glide'\n\nconst fastify = Fastify()\n\nconst valkey = await GlideClient.createClient({\n  addresses: [{ host: 'localhost', port: 6379 }]\n})\n\nfastify\n  .register(fastifyValkey, {\n    addresses: [{ host: '127.0.0.1', port: 6380 }],\n    namespace: 'hello'\n  })\n\nfastify\n  .register(fastifyValkey, {\n    client: valkey,\n    namespace: 'world'\n  })\n\n// Here we will use the `hello` named instance\nfastify.post('/hello', (request, reply) =\u003e {\n  fastify.valkey['hello'].set(request.body.key, request.body.value, (err) =\u003e {\n    reply.send(err || { status: 'ok' })\n  })\n})\n\nfastify.get('/hello', (request, reply) =\u003e {\n  fastify.valkey.hello.get(request.query.key, (err, val) =\u003e {\n    reply.send(err || val)\n  })\n})\n\n// Here we will use the `world` named instance\nfastify.post('/world', (request, reply) =\u003e {\n  fastify.valkey.world.set(request.body.key, request.body.value, (err) =\u003e {\n    reply.send(err || { status: 'ok' })\n  })\n})\n\nfastify.get('/world', (request, reply) =\u003e {\n  fastify.valkey['world'].get(request.query.key, (err, val) =\u003e {\n    reply.send(err || val)\n  })\n})\n\ntry {\n  await fastify.listen({ port: 3000 })\n} catch (err) {\n  fastify.log.error(err)\n  process.exit(1)\n}\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofek29%2Ffastify-valkey-glide-dev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fofek29%2Ffastify-valkey-glide-dev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fofek29%2Ffastify-valkey-glide-dev/lists"}