{"id":19070732,"url":"https://github.com/powerdns/redis-ipprefix","last_synced_at":"2026-02-04T00:02:31.923Z","repository":{"id":143359664,"uuid":"74405089","full_name":"PowerDNS/redis-ipprefix","owner":"PowerDNS","description":"Experiments in storing IP prefix data in Redis","archived":false,"fork":false,"pushed_at":"2016-11-22T13:54:13.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-13T21:51:31.756Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PowerDNS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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-11-21T20:56:46.000Z","updated_at":"2024-12-11T01:27:16.000Z","dependencies_parsed_at":"2023-06-11T01:30:35.536Z","dependency_job_id":null,"html_url":"https://github.com/PowerDNS/redis-ipprefix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PowerDNS/redis-ipprefix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDNS%2Fredis-ipprefix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDNS%2Fredis-ipprefix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDNS%2Fredis-ipprefix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDNS%2Fredis-ipprefix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PowerDNS","download_url":"https://codeload.github.com/PowerDNS/redis-ipprefix/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerDNS%2Fredis-ipprefix/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29062483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T23:14:54.203Z","status":"ssl_error","status_checked_at":"2026-02-03T23:14:50.873Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-09T01:20:11.094Z","updated_at":"2026-02-04T00:02:31.902Z","avatar_url":"https://github.com/PowerDNS.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Experiments in storing IP prefix data in Redis\n\nRandom ramblings below. This README currently lags behind the code.\n\nTest with `diff -u expected_output \u003c(./redis-ip.py )`\n\n## IPv4\n\n```\n127.0.0.1:6379\u003e zadd foo 8 vijf-acht\n(integer) 1\n127.0.0.1:6379\u003e zadd foo 13 zeven-dertien\n(integer) 1\n127.0.0.1:6379\u003e zrangebyscore foo 13 inf\n1) \"zeven-dertien\"\n127.0.0.1:6379\u003e zrangebyscore foo 8 inf\n1) \"vijf-acht\"\n2) \"zeven-dertien\"\n```\n\nIf we assume no overlapping subnets, we can add `LIMIT 0 1` to the zrangebyscore. If we assume overlap, we can limit it a small number (20-50) and evaluate them all, fetching more if necessary. (Or: we make sure the lexical ordering gives us the smallest one first (this is not the full story it turns out)). We can put all of this in Redis-side Lua.\n\n### IPv6\n\nZSET scores are 64 bit floats, which gives us 53 bits of positive integer resolution. The idea is to split the v6 address into chunks that we can 'stack'. 128/53 = 2.4 so we could do this in 3 levels but for convenience I propose to do 4*32 bits.\n\n# 3 hashes + 1 zset\n\nWe could hash the first 3 chunks, doing a BYSCORE lookup only on the fourth chunk. This would mean 4 lookups for any address, but the code would be simpler than for the next option. However, it is likely that most setups will have /64, /56 or /48 boundaries, in which case fewer lookups seems better - although I wonder how '3 hash lookups + 1 zset lookup' compares, in terms of performance, to '2 zset lookups'.\n\n# 4 zsets\n\nIf instead we stack 4 zsets, any level could return a positive result, at least in a no-overlap situation. Even with overlaps we could probably provide a downward referral.\n\nBoth setups (4 zets or 3 hashes) do mean duplication for anything shorther than /97.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerdns%2Fredis-ipprefix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowerdns%2Fredis-ipprefix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerdns%2Fredis-ipprefix/lists"}