RedixClustered
Cluster support for Redix, and other stuff! Currently:
- Very WIP
- Needs documentation
- The pipelines aren't smart enough to deal with keys on different nodes
Ported from some other PRX applications, and working to improve.
Installation
Add redix_clustered to your list of dependencies in mix.exs:
def deps do
[
{:redix_clustered, "~> 1.0.0"}
]
endThen just add your cluster as a child of your application:
children = [
{RedixClustered, host: "127.0.0.1", port: 6379, namespace: "my-ns"}
]Options you can pass to the RedixClustered spec:
hostthe hostname or IP of your redis cluster (default"127.0.0.1")portthe port of your redis cluster (default6379)usernamepassed to Redixpasswordpassed to Redixtimeoutpassed to Redixnameoptional name used to access your cluster, and also the supervision :namenamespaceoptional prefix to add to your redis keyspool_sizethe number of Redix connections to establish per node (default1)request_optsoptional Keyword list of options to pass to eachRedix.command/Redix.pipelinecall
And then you can run commands/pipelines:
{:ok, _pid} = RedixClustered.start_link()
{:ok, _pid} = RedixClustered.start_link(name: :red2, namespace: "ns2")
RedixClustered.command(["set", "foo", "val1"])
#
RedixClustered.command(:red2, ["set", "foo", "val2"])
#
RedixClustered.command(["get", "foo"])
#
RedixClustered.command(:red2, ["get", "foo"])
#
RedixClustered.command(:red2, ["get", "ns2:foo"], namespace: false)
# Or if you want to clone set commands to a 2nd redis cluster:
clone = [host: "127.0.0.2", port: 6380, namespace: "ns2"]
children = [
{RedixClustered, host: "127.0.0.1", namespace: "ns1", clone: clone}
]License
Contributing
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request