Skip to content

Commit

Permalink
Add support for nil type in Lua and Redis code
Browse files Browse the repository at this point in the history
This commit adds the ability to handle nil types in both Lua code and Redis commands. It involves updates to two areas - 'rediscli.go' in the server lua library and 'const.go' in the global settings. Now, the system can correctly recognize and process the nil type.

Signed-off-by: Christian Roessner <c@roessner.co>
  • Loading branch information
Christian Roessner committed Jul 3, 2024
1 parent 6094956 commit 09c0bb8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/global/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,9 @@ const (

// TypeBoolean represents a boolean type
TypeBoolean = "bool"

// TypeNil represents the nil value type
TypeNil = "nil"
)

const (
Expand Down
4 changes: 4 additions & 0 deletions server/lualib/rediscli.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func convertLuaValue(lValue lua.LValue) (any, error) {
return float64(lua.LVAsNumber(lValue)), nil
case lua.LTBool:
return lua.LVAsBool(lValue), nil
case lua.LTNil:
return nil, nil
default:
err := fmt.Errorf("unable to convert Lua value of type %s", lValue.Type())

Expand Down Expand Up @@ -72,6 +74,8 @@ func convertStringCmd(value *redis.StringCmd, valType string, L *lua.LState) err
} else {
return err
}
case global.TypeNil:
L.Push(lua.LNil)
default:
return fmt.Errorf("unable to convert string command of type %s", valType)
}
Expand Down

0 comments on commit 09c0bb8

Please sign in to comment.