8000 Compat: *SCAN with COUNT 0 errors (Redis returns empty for a missing key); Lua implicit 'arg' in vararg functions missing · Issue #820 · kividbio/kividb · GitHub
[go: up one dir, main page]

Skip to content

Compat: *SCAN with COUNT 0 errors (Redis returns empty for a missing key); Lua implicit 'arg' in vararg functions missing #820

Closed

Description

@murtazayusuf

Summary

Two Redis-compatibility gaps found while running real Ruby gems' test suites against kividb/kividb:v1.2.2-lua and Redis 8.10.3 side by side.

1. ZSCAN/SSCAN/HSCAN with COUNT 0 return ERR syntax error

Redis returns an empty result for a *SCAN on a key that does not exist before it looks at COUNT, and accepts COUNT 0 for SSCAN/HSCAN on existing keys too. KiviDB rejects all of these:

Command Redis 8.10.3 KiviDB 1.2.2
ZSCAN missing 0 MATCH * COUNT 0 0, [] ERR syntax error
ZSCAN existing 0 MATCH * COUNT 0 ERR syntax error ERR syntax error
SSCAN existing 0 COUNT 0 0, [] ERR syntax error
HSCAN existing 0 COUNT 0 0, {} ERR syntax error
SCAN 0 COUNT 0 ERR syntax error ERR syntax error

Real-world hit: sidekiq-unique-jobs 8.1.0 (used by Mastodon) sizes its ZSCAN by ZCARD, so with an empty digest set it sends ZSCAN uniquejobs:expiring_digests 0 match * count 0. On KiviDB the Sidekiq Web "delete all locks" action raises ERR syntax error; 3 of its specs fail (spec/sidekiq_unique_jobs/web_spec.rb:177, :200, :239), all passing on Redis. Captured with MONITOR on both servers.

2. Lua: implicit arg table in vararg functions (Lua 5.1 compatibility)

Redis's Lua 5.1 is built with LUA_COMPAT_VARARG, so a vararg function can read its arguments as the implicit table arg:

local function log_debug(...)
  local result = ""
  for _, v in ipairs(arg) do result = result .. " " .. tostring(v) end
  return result
end
return log_debug("a", "b")

Redis 8.10.3 runs this; KiviDB (Lua 5.4) fails with ERR Script attempted to access nonexistent global variable 'arg'. Seen in sidekiq-unique-jobs' test fixture spec/support/lua/shared/_common.lua (2 specs fail: script/client_spec.rb:22, script/scripts_spec.rb:47); the gem's shipped scripts use {...} and pass. Older scripts in the wild use this 5.0/5.1 idiom. Related to #747 (other Lua 5.4 number rules).

Results of the full suites (same host, both servers fresh)

Suite Redis 8.10.3 KiviDB 1.2.2-lua
stoplight v5.8.3 (Mastodon's version) 765 examples, 0 failures 765 examples, 0 failures
sidekiq-scheduler v6.0.2 274 examples, 5 failures 274 examples, the same 5 failures (Web UI, env)
sidekiq-unique-jobs v8.1.0 1069 examples, 1 failure (latency-sensitive) 1069 examples, 6 failures (the same 1 + the 5 above)

Environment

kividb/kividb:v1.2.2-lua (INFO redis_version:8.10.0) and redis:8 (8.10.3, --save ""), each started fresh; Ruby 3.4, suites run with --order defined from inside the server's network namespace; AWS CodeBuild linux x86_64.

Activity

  1. murtazayusuf commented on Nov 15, 2026

    @murtazayusuf
    ContributorAuthor

    Correction to the table above, checked against real Redis 8.10.2 and 8.10.3 while fixing this (#828): SSCAN existing 0 COUNT 0 and HSCAN existing 0 COUNT 0 answer ERR syntax error on Redis too, for every encoding. Only the missing-key rows differ from KiviDB: Redis looks the key up before reading the options, so a missing key answers 0 and an empty list whatever follows the cursor. #828 fixes that. The Lua implicit arg part stays open: it is created per call inside the Lua 5.1 VM, so it needs a VM change or #756.

  2. added a commit that references this issue on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0