redis_func_cache.mixins.hash module#
- class redis_func_cache.mixins.hash.AbstractHashMixin[source]#
Bases:
ABCAn abstract mixin class for hash function name, source code, and arguments.
The hash result is used inside the redis (ordered) set and hash map in redis, aka the sub-key.
Do NOT use the mixin class directly. Inherit it and override the
__hash_config__to define the algorithm and serializer.Example
class JsonMd5B64HashMixin(AbstractHashMixin): __hash_config__ = HashConfig( algorithm="md5", serializer=lambda x: json.dumps(x).encode(), decoder=lambda x: b64encode(x.digest()), )
- __hash_config__#
Configure of how to calculate hash for a function.
- Type:
- calc_hash(f=None, args=None, kwds=None)[source]#
Mixin method to overwrite
redis_func_cache.policies.abstract.AbstractPolicy.calc_hash()All other mixin classes in the module inherit this mixin class, and their
hashvalue are all return by the method.They use different hash algorithms and serializers defined in the class attribute
__hash_config__to generate differenthashvalue.- Parameters:
- Return type:
bytes|str|memoryview- Returns:
The hash value of the function.
- Raises:
TypeError – If the function is not callable.
- class redis_func_cache.mixins.hash.HashConfig(algorithm, serializer, decoder=None, use_bytecode=True)[source]#
Bases:
objectA
dataclasses.dataclass()Configurator forAbstractHashMixin- Parameters:
- decoder: Callable[[Hash], bytes | str | memoryview] | None = None#
function to decode hash digest to member of a sorted/unsorted set and also field name of a hash map in redis.
Default is
None, means no decoding and to use the raw digest bytes directly.
- class redis_func_cache.mixins.hash.JsonMd5Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the MD5 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.JsonMd5HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the MD5 hash value, and finally returns the digest as bytes.
- class redis_func_cache.mixins.hash.JsonMd5HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the MD5 hash value, and finally returns the hexadecimal representation of the digest.
- class redis_func_cache.mixins.hash.JsonSha1Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA1 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.JsonSha1HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA1 hash value, and finally returns the digest as bytes.
- class redis_func_cache.mixins.hash.JsonSha1HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA1 hash value, and finally returns the hexadecimal representation of the digest.
- class redis_func_cache.mixins.hash.JsonSha256Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA256 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.JsonSha256HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA256 hash value, and finally returns the digest as bytes.
- class redis_func_cache.mixins.hash.JsonSha256HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA256 hash value, and finally returns the hexadecimal representation of the digest.
- class redis_func_cache.mixins.hash.JsonSha512Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA512 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.JsonSha512HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA512 hash value, and finally returns the digest as bytes.
- class redis_func_cache.mixins.hash.JsonSha512HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
jsonmodule, then calculates the SHA512 hash value, and finally returns the hexadecimal representation of the digest.
- class redis_func_cache.mixins.hash.PickleMd5Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the MD5 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.PickleMd5HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the MD5 hash value, and finally returns the digest as bytes.It is the default hash mixin.
- class redis_func_cache.mixins.hash.PickleMd5HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the MD5 hash value, and finally returns the hexadecimal representation of the digest.
- class redis_func_cache.mixins.hash.PickleSha1Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA1 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.PickleSha1HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA1 hash value, and finally returns the digest as bytes.
- class redis_func_cache.mixins.hash.PickleSha1HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA1 hash value, and finally returns the hexadecimal representation of the digest.
- class redis_func_cache.mixins.hash.PickleSha256Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA256 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.PickleSha256HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA256 hash value, and finally returns the digest as bytes.
- class redis_func_cache.mixins.hash.PickleSha256HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA256 hash value, and finally returns the hexadecimal representation of the digest.
- class redis_func_cache.mixins.hash.PickleSha512Base64HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA512 hash value, and finally returns the base64 encoded digest.
- class redis_func_cache.mixins.hash.PickleSha512HashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA512 hash value, and finally returns the digest as bytes.
- class redis_func_cache.mixins.hash.PickleSha512HexHashMixin[source]#
Bases:
AbstractHashMixinSerializes the function name, source code, and arguments using the
picklemodule, then calculates the SHA512 hash value, and finally returns the hexadecimal representation of the digest.