{"id":14977760,"url":"https://github.com/firstbatchxyz/warp-contracts-redis","last_synced_at":"2025-10-28T05:31:08.463Z","repository":{"id":104302229,"uuid":"606803419","full_name":"firstbatchxyz/warp-contracts-redis","owner":"firstbatchxyz","description":"Redis plugin for Warp Contracts SortKeyCache interface","archived":false,"fork":false,"pushed_at":"2024-02-02T18:03:20.000Z","size":359,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T12:11:12.744Z","etag":null,"topics":["arweave","cache","redis","warp-contracts"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/warp-contracts-redis","language":"TypeScript","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/firstbatchxyz.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}},"created_at":"2023-02-26T16:05:29.000Z","updated_at":"2024-05-08T15:02:56.000Z","dependencies_parsed_at":"2024-10-29T09:03:05.165Z","dependency_job_id":null,"html_url":"https://github.com/firstbatchxyz/warp-contracts-redis","commit_stats":{"total_commits":42,"total_committers":3,"mean_commits":14.0,"dds":"0.33333333333333337","last_synced_commit":"15d9a634b3bc21ba6c6ceebf8b42419d1c911c4c"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstbatchxyz%2Fwarp-contracts-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstbatchxyz%2Fwarp-contracts-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstbatchxyz%2Fwarp-contracts-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstbatchxyz%2Fwarp-contracts-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstbatchxyz","download_url":"https://codeload.github.com/firstbatchxyz/warp-contracts-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238603665,"owners_count":19499488,"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":["arweave","cache","redis","warp-contracts"],"created_at":"2024-09-24T13:56:16.360Z","updated_at":"2025-10-28T05:31:01.155Z","avatar_url":"https://github.com/firstbatchxyz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![NPM](https://img.shields.io/npm/v/warp-contracts-redis?logo=npm\u0026color=CB3837)](https://www.npmjs.com/package/warp-contracts-redis)\n![Test Workflow](https://github.com/firstbatchxyz/warp-contracts-redis/actions/workflows/test.yml/badge.svg?branch=master)\n\n# Warp Contracts Redis Cache\n\n\u003e Warp Contracts SortKeyCache implementation using [Redis](https://redis.io/).\n\nWarp Contracts will `open` and `close` the client many times, and we have seen that this causes unexpected errors sometimes, mostly due to client being closed. Furthermore, we would like to have an \"online\" cache option rather than local caches too. That is why this package was developed.\n\n`RedisCache` solves the `open` and `close` problem with a \"managed\" setting. Instead of providing a URL, you can provide the Redis client itself. The effects of doing that are as follows:\n\n- `open` function will be disabled, calling it will have no effect; it is user's responsibility to connect.\n- `close` function will be disabled, calling it will have no effect; it is user's responsibility to disconnect.\n- the user should make the necessary configurations for `inMemory: true` option; a static function is exposed for this purpose: `setConfigForInMemory`.\n- you can see if the client is managed or not via the `isManaged` field.\n\nSome of the functionality is achieved via [Lua](https://www.lua.org/home.html) scripts (v5.1), which you can find under `src/lua` for _reference_; the actual scripts are written in `luaScripts.ts`. The `prefix` and `subLevelSeparator` must be provided as argument to Lua scripts, because multiple `RedisCache` instances may be created with different prefixes or sub-level separators but they may connect to the same client; and for that reason we can't simply hardcode them in the script.\n\n\u003e [!TIP]\n\u003e\n\u003e To learn more about SortKeyCache, see the links below:\n\u003e\n\u003e - [SortKeyCache](https://github.com/warp-contracts/warp/blob/main/src/cache/SortKeyCache.ts)\n\u003e - [Warp docs for SortKey](https://academy.warp.cc/docs/sdk/advanced/bundled-interaction#how-it-works)\n\u003e - [KV class of SmartWeave](https://github.com/warp-contracts/warp/blob/main/src/legacy/smartweave-global.ts#L260)\n\n## Installation\n\nYou can install the NPM package as shown below:\n\n```sh\nnpm i warp-contracts-redis\nyarn add warp-contracts-redis\npnpm add warp-contracts-redis\n```\n\n## Usage\n\nThe `RedisCache` constructor takes two inputs, one is of type `CacheOptions` as is the case for all `SortKeyCache` implementations of Warp Contracts. The other is Redis-specific options.\n\n```ts\nimport type { CacheOptions } from \"warp-contracts\";\nimport type { RedisOptions } from \"warp-contracts-redis\";\n\nconst cacheOptions = {\n  // does not dump on close\n  inMemory: true,\n\n  // acts as a prefix for all keys\n  dbLocation: \"redis.location\",\n\n  // separates key from sortKey\n  subLevelSeparator: \"|\",\n} satisfies CacheOptions;\n\nconst redisOptions = {\n  // redis connection url\n  url: \"redis://default:redispw@localhost:6379\",\n\n  // leave at least this many on pruning\n  minEntriesPerContract: 10,\n\n  // after this many entries, prune\n  maxEntriesPerContract: 100,\n} satisfies RedisOptions;\n\nconst redisCache = new RedisCache(cacheOptions, redisOptions);\n```\n\nFor the managed version, simply create your `ioredis` client outside and pass it within `redisOptions` similar to the example above; do not pass in URL.\n\n## Test\n\nTests require a Redis server running at the specified URL within `tests/constants`. We use the default Redis URL for that, if you would like to run tests on a custom URL you must change the URL within the constants file.\n\n```sh\npnpm test         # test everything\npnpm test \u003cpath\u003e  # test a specific suite\n```\n\n## Building\n\nBuild the package with:\n\n```sh\npnpm build\n```\n\n## Styling\n\nCheck styling with:\n\n```sh\npnpm format\npnpm lint\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstbatchxyz%2Fwarp-contracts-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstbatchxyz%2Fwarp-contracts-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstbatchxyz%2Fwarp-contracts-redis/lists"}