From 466411d7838b1ec20bef4e1419bdecb837f3f913 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 1 Apr 2024 11:57:54 +0200 Subject: [PATCH] Hard code redis.REDIS_VERSION to 7.2.4 Fixes: https://codeberg.org/redict/redict/issues/37 Signed-off-by: Drew DeVault --- src/script_lua.c | 9 +++++++++ tests/unit/functions.tcl | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/script_lua.c b/src/script_lua.c index 9b35180f8..135894ca1 100644 --- a/src/script_lua.c +++ b/src/script_lua.c @@ -1369,6 +1369,15 @@ void luaRegisterVersion(lua_State* lua) { lua_pushstring(lua,"REDICT_VERSION"); lua_pushstring(lua,REDICT_VERSION); lua_settable(lua,-3); + + /* Hard-coded to 7.2.4 for forward compatibility: */ + lua_pushstring(lua,"REDIS_VERSION_NUM"); + lua_pushnumber(lua,0x070204); + lua_settable(lua,-3); + + lua_pushstring(lua,"REDIS_VERSION"); + lua_pushstring(lua,"7.2.4"); + lua_settable(lua,-3); } void luaRegisterLogFunction(lua_State* lua) { diff --git a/tests/unit/functions.tcl b/tests/unit/functions.tcl index 032ab2014..8c517f5f7 100644 --- a/tests/unit/functions.tcl +++ b/tests/unit/functions.tcl @@ -1132,6 +1132,26 @@ start_server {tags {"scripting"}} { assert {$v1 eq $v2 || [string match "$v1-r*" $v2]} } + test {FUNCTION - legacy redis version is hard-coded to 7.2.4} { + r FUNCTION load replace {#!lua name=test + local version = redis.REDIS_VERSION_NUM + + redict.register_function{function_name='get_version_v1', callback=function() + return string.format('%s.%s.%s', + bit.band(bit.rshift(version, 16), 0x000000ff), + bit.band(bit.rshift(version, 8), 0x000000ff), + bit.band(version, 0x000000ff)) + end} + redis.register_function{function_name='get_version_v2', callback=function() return redis.REDIS_VERSION end} + } + + catch {[r fcall f1 0]} e + set v1 [r fcall get_version_v1 0] + set v2 [r fcall get_version_v2 0] + # Permanently hard-coded to 7.2.4 + assert {$v1 eq "7.2.4" && $v1 eq $v2} + } + test {FUNCTION - function stats} { r FUNCTION FLUSH