Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prx/redix-clustered
Hex package to run redix + clustered + pooling + etc
https://github.com/prx/redix-clustered
Last synced: 16 days ago
JSON representation
Hex package to run redix + clustered + pooling + etc
- Host: GitHub
- URL: https://github.com/prx/redix-clustered
- Owner: PRX
- License: mit
- Created: 2021-10-06T16:03:02.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-06T14:18:23.000Z (7 months ago)
- Last Synced: 2024-11-16T04:19:38.517Z (about 1 month ago)
- Language: Elixir
- Size: 62.5 KB
- Stars: 2
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RedixClustered
Cluster support for Redix, and other stuff! Currently:
1. Very WIP
2. Needs documentation
3. The pipelines aren't smart enough to deal with keys on different nodesPorted from some other PRX applications, and working to improve.
## Installation
Add `redix_clustered` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:redix_clustered, "~> 1.0.0"}
]
end
```Then just add your cluster as a child of your application:
```elixir
children = [
{RedixClustered, host: "127.0.0.1", port: 6379, namespace: "my-ns"}
]
```Options you can pass to the RedixClustered spec:
- `host` the hostname or IP of your redis cluster (default `"127.0.0.1"`)
- `port` the port of your redis cluster (default `6379`)
- `username` passed to Redix
- `password` passed to Redix
- `timeout` passed to Redix
- `name` optional name used to access your cluster, and also the supervision [:name](https://hexdocs.pm/elixir/1.12/Supervisor.html#start_link/2)
- `namespace` optional prefix to add to your redis keys
- `pool_size` the number of Redix connections to establish per node (default `1`)
- `request_opts` optional Keyword list of options to pass to each `Redix.command` / `Redix.pipeline` callAnd then you can run commands/pipelines:
```elixir
{:ok, _pid} = RedixClustered.start_link()
{:ok, _pid} = RedixClustered.start_link(name: :red2, namespace: "ns2")RedixClustered.command(["set", "foo", "val1"])
# {:ok, "OK"}RedixClustered.command(:red2, ["set", "foo", "val2"])
# {:ok, "OK"}RedixClustered.command(["get", "foo"])
# {:ok, "val1"}RedixClustered.command(:red2, ["get", "foo"])
# {:ok, "val2"}RedixClustered.command(:red2, ["get", "ns2:foo"], namespace: false)
# {:ok, "val2"}
```Or if you want to clone set commands to a 2nd redis cluster:
```elixir
clone = [host: "127.0.0.2", port: 6380, namespace: "ns2"]children = [
{RedixClustered, host: "127.0.0.1", namespace: "ns1", clone: clone}
]
```## License
[MIT License](LICENSE)
## Contributing
1. Fork it
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create new Pull Request