redis_func_cache.utils module#

redis_func_cache.utils.b64digest(x)[source]#

Convert hash digest to base64 string.

Parameters:

x (Hash) – The hash object.

Return type:

bytes

Returns:

The base64 encoded digest of the hash object.

This function takes a hash object (e.g., SHA256, MD5, etc.) and returns its digest, encoded in Base64 format, with “=” paddings stripped.

It is useful when you need to represent a hash value in a compact and readable format.

redis_func_cache.utils.clean_lua_script(source)[source]#

Remove comments and empty lines from a Lua script.

Parameters:

source (str) – The Lua script source code to be cleaned.

Return type:

str

Returns:

The cleaned Lua script as a string.

Note

This function utilizes the pygments library to remove comments and empty lines from the Lua script. If pygments is not installed, the source code will be returned unchanged.

redis_func_cache.utils.get_callable_bytecode(obj)[source]#

Retrieve the bytecode of the given callable object.

Parameters:

obj (Callable) – The function to retrieve bytecode from.

Return type:

bytes

Returns:

The bytecode of the function, or b”” if the function has no __code__ attribute.

redis_func_cache.utils.read_lua_file(file)[source]#

Read a Lua file from the package resources.

Parameters:

file (str) – The name of the Lua file to read.

Return type:

str

Returns:

The contents of the Lua file as a string.

This function locates and reads the entire text content of a specified Lua file. It uses the importlib.resources to locate the file.