RedixSharding

Drop-in replacement for Redix with sharding and pooling support

Usage

opts = [
  pools: [
    default: [
      urls: ["redis://localhost:6379", "redis://localhost:6380", "redis://localhost:6381", "redis://localhost:6382"],
      connection: 1],
    index: [
      urls: ["redis://localhost:6383", "redis://localhost:6384"],
      connection: 2]
  ]
]

RedixSharding.start_link(opts)

RedixSharding.command(["INCRBY", "{default@foo5}", 1])

RedixSharding.pipeline([["INCRBY", "{default@foo5}", 1]])

In the opts configuration above, we have configured 2 pools:

Sharding Rule:

There are 2 concepts you need to grasp here:

For commands that will require multiple keys, we will calculate the pool name and shard key for each key, and we would only run the command if all key maps to the same pool and same shard

full key pool name shard key
Foo:bar default Foo:bar
Foo{}bar default Foo{}bar
{Foo}bar default Foo
{default@Foo}bar default default@Foo
{index@Foo}bar index index@Foo
{@Foo}bar default @Foo
{Foo}:bar:{Baz} default Foo
{Foo}:bar:{index@Baz} default Foo