{"id":13777629,"url":"https://github.com/Kong/lua-resty-counter","last_synced_at":"2025-05-11T11:33:54.375Z","repository":{"id":66527178,"uuid":"218377913","full_name":"Kong/lua-resty-counter","owner":"Kong","description":"Lock-free counter for OpenResty","archived":false,"fork":false,"pushed_at":"2023-05-13T03:42:55.000Z","size":12,"stargazers_count":23,"open_issues_count":4,"forks_count":11,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-05-08T21:48:12.425Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","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/Kong.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}},"created_at":"2019-10-29T20:31:10.000Z","updated_at":"2025-02-22T11:32:46.000Z","dependencies_parsed_at":"2023-05-18T01:46:24.419Z","dependency_job_id":null,"html_url":"https://github.com/Kong/lua-resty-counter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kong%2Flua-resty-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kong","download_url":"https://codeload.github.com/Kong/lua-resty-counter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253559145,"owners_count":21927538,"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":[],"created_at":"2024-08-03T18:00:46.461Z","updated_at":"2025-05-11T11:33:54.028Z","avatar_url":"https://github.com/Kong.png","language":"Perl","readme":"Name\n====\n\nlua-resty-counter - Lock-free counter for OpenResty.\n\n![Build Status](https://travis-ci.com/kong/lua-resty-counter.svg?branch=master) ![luarocks](https://img.shields.io/luarocks/v/kong/lua-resty-counter?color=%232c3e67)\n\nTable of Contents\n=================\n\n- [Description](#description)\n- [Status](#status)\n- [API](#api)\n- [TODO](#todo)\n- [Copyright and License](#copyright-and-license)\n- [See Also](#see-also)\n\n\nDescription\n===========\n\nWhen number of workers increase, the penalty of acquiring a lock becomes noticable.\nThis library implements a lock-free counter that does incrementing operation in worker's Lua VM.\nEach worker then sync its local counter to a shared dict timely.\n\n\n[Back to TOC](#table-of-contents)\n\nStatus\n========\n\nProduction\n\nAPI\n========\n\n## counter.new\n\n**syntax**: *c, err = counter.new(shdict_name, sync_interval?)*\n\nCreate a new counter instance. Take first argument as the shared dict name in\nstring. And an optional second argument as interval to sync local state to\nshared dict in number. If second argument is omitted, local counter will not be\nsynced automatically, user are responsible to call `counter:sync` on each worker.\n\n[Back to TOC](#table-of-contents)\n\n## counter.sync\n\n**syntax**: *ok = counter:sync()*\n\nSync current worker's local counter to shared dict. Not needed if a counter is\ncreated with `sync_interval` not set to `nil`.\n\n[Back to TOC](#table-of-contents)\n\n## counter.incr\n\n**syntax**: *counter:incr(key, step?)*\n\nIncrease counter of key `k` with a step of `step`. If `step` is omitted, it's\ndefault to `1`.\n\n[Back to TOC](#table-of-contents)\n\n## counter.reset\n\n**syntax**: *newval, err, forcible? = counter:reset(key, number)*\n\nReset the counter in shdict with a decrease of `number`. This function is a wrapper of\n`ngx.shared.DICT:incr(key, -number, number)`, please refer to\n[lua-nginx-module doc](https://github.com/openresty/lua-nginx-module#ngxshareddictincr)\nfor return values.\n\n[Back to TOC](#table-of-contents)\n\n## counter.get\n\n**syntax**: *value = counter:get(key)*\n\nGet the value of counter from shared dict.\n\n[Back to TOC](#table-of-contents)\n\n## counter.get_keys\n\n**syntax**: *keys = counter:get_keys(max_count?)*\n\nGet the keys of counters in shared dict. This function is a wrapper of\n`ngx.shared.DICT:get_keys`, please refer to\n[lua-nginx-module doc](https://github.com/openresty/lua-nginx-module#ngxshareddictget_keys)\nfor return values.\n\n[Back to TOC](#table-of-contents)\n\n\nTODO\n====\n\n[Back to TOC](#table-of-contents)\n\n\nCopyright and License\n=====================\n\nThis module is licensed under the Apache 2.0 license.\n\nCopyright (C) 2019, Kong Inc.\n\nAll rights reserved.\n\n[Back to TOC](#table-of-contents)\n\nSee Also\n========\n* [lua-nginx-module](https://github.com/openresty/lua-nginx-module)\n\n[Back to TOC](#table-of-contents)\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKong%2Flua-resty-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKong%2Flua-resty-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKong%2Flua-resty-counter/lists"}