ex_sider v0.2.0 RedisCache

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)

This 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.

Summary

Functions

Delete 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 RedisCache, overwriting existing fields in the cache and possibly causing local (unpushed) changes

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 RedisCache

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

delete(container)

Delete this hash from the Redis repo and clear the local cache, if any.

dump(redis_cache)

Returns the underlying cached map. This does not pull in changes beforehand!

merge(container, other_map)

Merges the fields of the given map into the RedisCache, overwriting existing fields in the cache and possibly causing local (unpushed) changes.

new(redis_key)

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)
new(redis_key, opts)
pull(container)

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 RedisCache.

push(container)

Push all local keys/values back to the Redis repo. This simply overwrites whatever is already in there.

unpushed_changes?(redis_cache)

Check if we have local unpushed changes.