Skip to content

Conversation

@vyavdoshenko
Copy link

This PR adds compatibility with Dragonfly - a Redis-compatible in-memory store. Two issues are addressed:

  1. Undeclared keys in Lua scripts

Dragonfly requires all keys accessed in Lua scripts to be declared upfront in the KEYS array, or the script must explicitly opt out using the --!df flags=allow-undeclared-keys directive.

Cacheops dynamically generates conjunction keys (conj:*) inside Lua scripts, which causes failures in Dragonfly without this flag.

Related Dragonfly issues:

  1. cjson integer formatting difference

Dragonfly's cjson.decode converts JSON integers to Lua floats, causing tostring(1) to return "1.0" instead of "1". This broke cache key matching between Python-generated keys and Lua-generated keys:

Python: conj:auth_user:id=1
Lua:    conj:auth_user:id=1.0  ← mismatch!

Added format_val() helper function to format integers without a decimal point.

Changes:

  • Added --!df flags=allow-undeclared-keys directive to all Lua scripts
  • Added format_val() function to handle integer formatting consistently

Testing:

Dragonfly:

# Start Dragonfly
docker run -d --name dragonfly -p 6379:6379 docker.dragonflydb.io/dragonflydb/dragonfly

# Run tests
pytest

Redis compatibility:
Tested with Redis 4.x and Redis 7.x - all tests pass:

Redis 4:

docker run -d --name redis4 -p 6379:6379 redis:4-alpine
pytest

Redis 7:

docker run -d --name redis7 -p 6379:6379 redis:7-alpine
pytest

Notes:

  • The --!df directive is a Lua comment, so it's safely ignored by Redis
  • The format_val() fix is defensive and works correctly on both Redis and Dragonfly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant