ex_sider v0.1.3 RedisHash
Currently only works by merging/replacing with maps and then pull/push-ing.
In the future, this should implement Access
, Enumerable
and Collectable
- meaning
this could then be used with Elixir’s Enum
w/o limitations. These should work
independant of whether or not local caching is used.
You can let this cache its values locally and commit them back to the repo on demand. This doesn’t handle inconsistencies etc. - the use case is to have a relatively longer term storage (redis semantics) for process related data. In case a process gets restarted etc. it can quickly commit and refetch its state later on. Obviously gets tricky if multiple processes use the same redis-hash.
Conflicts and race conditions are tried to be avoided, but essentially this is a very simplistic grow-only set. (You can delete the whole thing, but not single entries for now)
Local caching
Local caching will fetch the state of the hash when it is created, and will try to keep it up to date with the external version whenever you do pulls and pushes to redis.
This can be disabled by using:
RedisHash.new("my-key", local_cache: false)
When local caching is disabled, every merge etc. automatically leads to a push to redis. In order to get the state from redis then, you’ll need manually pull and dump.
Summary
Functions
Clear this hash from the Redis repo and clear the local cache, if any
Returns the underlying cached map. This does not pull in changes beforehand!
Merges the fields of the given map into the RedisHash, overwriting existing fields in the cache and possibly causing local (unpushed) changes
If local caching is enabled, this will checkout the initial cache state from redis upon creation
Pulls all fields of this hash from Redis and merges it with the current local cache if any. This doesn’t change the local-cache state of the RedisHash
Push all local keys/values back to the Redis repo. This simply overwrites whatever is already in there
Check if we have local unpushed changes
Functions
Merges the fields of the given map into the RedisHash, overwriting existing fields in the cache and possibly causing local (unpushed) changes.
If this is used with a non-local-cached RedisHash, the given map is merged directly into the Redis hash in the redis repo!
If local caching is enabled, this will checkout the initial cache state from redis upon creation.
Options:
:binary_mode
- true/false depending on whether data should be put through:erlang.term_to_binary
and:erlang.binary_to_term
respectively or not (default: true):local_cache
- true/false to enable or disable local caching (default: true)
Pulls all fields of this hash from Redis and merges it with the current local cache if any. This doesn’t change the local-cache state of the RedisHash.
Push all local keys/values back to the Redis repo. This simply overwrites whatever is already in there.