{"id":19232639,"url":"https://github.com/makeomatic/redis-filtered-sort","last_synced_at":"2025-07-24T08:39:00.600Z","repository":{"id":3319377,"uuid":"49001559","full_name":"makeomatic/redis-filtered-sort","owner":"makeomatic","description":"Exports LUA script, which is able to perform multi filter operations, as well as sorts","archived":false,"fork":false,"pushed_at":"2023-09-03T01:32:46.000Z","size":1220,"stargazers_count":4,"open_issues_count":8,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-28T02:03:01.296Z","etag":null,"topics":["redis","sorts"],"latest_commit_sha":null,"homepage":null,"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/makeomatic.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":"2016-01-04T14:21:15.000Z","updated_at":"2022-01-04T23:52:34.000Z","dependencies_parsed_at":"2024-06-19T17:12:49.706Z","dependency_job_id":"6c8f7360-4a7a-46ac-93f2-c8be87a1eff0","html_url":"https://github.com/makeomatic/redis-filtered-sort","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/makeomatic/redis-filtered-sort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makeomatic%2Fredis-filtered-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makeomatic%2Fredis-filtered-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makeomatic%2Fredis-filtered-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makeomatic%2Fredis-filtered-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makeomatic","download_url":"https://codeload.github.com/makeomatic/redis-filtered-sort/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makeomatic%2Fredis-filtered-sort/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266815226,"owners_count":23988563,"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","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["redis","sorts"],"created_at":"2024-11-09T16:07:00.911Z","updated_at":"2025-07-24T08:38:58.579Z","avatar_url":"https://github.com/makeomatic.png","language":"JavaScript","readme":"# redis-filtered-sort\n\n[![Build Status](https://travis-ci.org/makeomatic/redis-filtered-sort.svg)](https://travis-ci.org/makeomatic/redis-filtered-sort)\n\nExports LUA script, which is able to perform multi filter operations, as well as sorts\n\nThis basically replicates `http://redis.io/commands/sort` but with extra features and ability to run it in clustered mode with\nhashed keys, which resolve to the same slot\n\n## Installation\n\n`npm i redis-filtered-sort -S`\n\n## Usage\n\n```js\nconst { filter: strFilter, attach } = require('redis-filtered-sort');\nconst Redis = require('ioredis');\nconst redis = new Redis();\n\n// adds redis.sortedFilteredList command to redis instance\nattach(redis, 'fsort');\n\n// raw Buffer of lua script\n// filteredSort.script\n\nconst filter = strFilter({\n  // only ids with `!mamba%` in them will be presented. Internally it uses lua string.find, so regexp is possible. Escape special chars\n  // with % or use escape helper for that\n  '#': '!mamba%',\n  priority: {\n    gte: 10, // only ids, which have priority greater or equal to 10 will be returned\n  },\n  name: 'love', // only ids, which have 'name' containing 'love' in their metadata will be returned\n});\nconst offset = 10;\nconst limit = 20;\nconst sortBy = 'priority';\nconst expiration = 30000; // ms\n\n// perform op\nconst currentTime = Date.now();\n\nredis\n  .fsort('set-of-ids', 'metadata*', sortBy, 'DESC', filter, currentTime, offset, limit, expiration)\n  .then(data =\u003e {\n    // how many items in the complete list\n    // rest of the data is ids from the 'set-of-ids'\n    const sortedListLength = parseInt(data.pop(), 10);\n\n    // at this point you might want to populate ids with actual data about them\n    // for instance, like this:\n    return Promise.map(data, function populateData(id) {\n      return Promise.props({\n        id,\n        data: redis.hgetall('metadata' + id),\n      });\n    });\n  });\n```\n\n### Aggregate functions\n\n1. use fsort to generate list of ids\n2. pass that id to aggregate function and receive results back\n\n```js\nredis\n  .fsortAggregate(ID_LIST_KEY, META_KEY_PATTERN, mod.filter({\n    age: 'sum'\n  }))\n  .then(JSON.parse)\n  .get('age')\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakeomatic%2Fredis-filtered-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakeomatic%2Fredis-filtered-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakeomatic%2Fredis-filtered-sort/lists"}