redix_cluster v0.0.2 RedixCluster

This module provides the main API to interface with Redis Cluster by Redix.

Overview

Module.FuncDescription
RedixCluster.start/2start redixcluster application
RedixCluster.command/2RedixCluster.command(~w(SET mykey foo))
RedixCluster.pipeline/2RedixCluster.pipeline([~w(SET mykey foo)])
RedixCluster.transaction/2RedixCluster.transaction([~w(SET mykey foo)])

Require

Make Sure CROSSSLOT Keys in request hash to the same slot

Examples

`Same hash keys`
iex> ~w(mget {user}123 {user}234 {user}456)

`Diff hash keys`
iex> ~w(mget {user1}123 {user2}234 {user3}456)
["mget", "{user1}123", "{user2}234", "{user3}456"]

Make sure all char is {} is the same

Link to this section Summary

Functions

Make sure CROSSSLOT Keys in request hash to the same slot

This function works exactly like RedixCluster.command/2 but

Callback invoked after code upgrade, if the application environment has changed.

Make sure CROSSSLOT Keys in request hash to the same slot

Make sure CROSSSLOT Keys in request hash to the same slot

Starts RedixCluster Application by config.exs

Make sure CROSSSLOT Keys in request hash to the same slot

Make sure CROSSSLOT Keys in request hash to the same slot

Link to this section Types

Link to this type

command()
command() :: [binary()]

Link to this section Functions

Link to this function

command(command, opts \\ [])
command(String.t(), Keyword.t()) ::
  {:ok, Redix.Protocol.redis_value()} | {:error, Redix.Error.t() | atom()}

Make sure CROSSSLOT Keys in request hash to the same slot

This function works exactly like Redix.command/3

Examples

iex> RedixCluster.command(~w(SET mykey foo))
{:ok, "OK"}

iex> RedixCluster.command(~w(GET mykey))
{:ok, "foo"}

iex> RedixCluster.command(~w(INCR mykey zhongwen))
{:error,
 %Redix.Error{message: "ERR wrong number of arguments for 'incr' command"}}

iex> RedixCluster.command(~w(mget ym d ))
{:error,
 %Redix.Error{message: "CROSSSLOT Keys in request don't hash to the same slot"}}

iex> RedixCluster.command(~w(mset {keysamehash}ym 1 {keysamehash}d 2 ))
{:ok, "OK"}

iex> RedixCluster.command(~w(mget {keysamehash}ym {keysamehash}d ))
{:ok, ["1", "2"]}
Link to this function

command!(command, opts \\ [])

This function works exactly like RedixCluster.command/2 but:

the error will be raised

## Examples

iex> RedixCluster.command!(~w(SET mykey foo))
"OK"

iex> RedixCluster.command!(~w(INCR mykey))
** (Redix.Error) ERR value is not an integer or out of range
   (redix_cluster) lib/redix_cluster.ex:40: RedixCluster.command!/2
Link to this function

config_change(changed, new, removed)

Callback invoked after code upgrade, if the application environment has changed.

changed is a keyword list of keys and their changed values in the application environment. new is a keyword list with all new keys and their values. removed is a list with all removed keys.

Callback implementation for Application.config_change/3.

Link to this function

pipeline(commands, opts \\ [])
pipeline([command()], Keyword.t()) ::
  {:ok, [Redix.Protocol.redis_value()]} | {:error, atom()}

Make sure CROSSSLOT Keys in request hash to the same slot

This function works exactly like Redix.pipeline/3

Examples

iex> RedixCluster.pipeline([~w(INCR mykey), ~w(INCR mykey), ~w(DECR mykey)])
{:ok, [1, 2, 1]}

iex> RedixCluster.pipeline([~w(SET {samehash}k3 foo), ~w(INCR {samehash}k2), ~w(GET {samehash}k1)])
{:ok, ["OK", 1, nil]}

iex> RedixCluster.pipeline([~w(SET {diffhash3}k3 foo), ~w(INCR {diffhash2}k2), ~w(GET {diffhash1}k1)])
{:error, :key_must_same_slot}
Link to this function

pipeline!(commands, opts \\ [])
pipeline!([command()], Keyword.t()) :: [Redix.Protocol.redis_value()]

Make sure CROSSSLOT Keys in request hash to the same slot

This function works exactly like RedixCluster.pipeline/2 but

the error will be raised

Examples

iex> RedixCluster.pipeline!([~w(INCR mykey), ~w(INCR mykey), ~w(DECR mykey)])
{:ok, [1, 2, 1]}

iex> RedixCluster.pipeline!([~w(SET {samehash}k3 foo), ~w(INCR {samehash}k2), ~w(GET {samehash}k1)])
{:ok, ["OK", 1, nil]}

iex> RedixCluster.pipeline!([~w(SET {diffhash3}k3 foo), ~w(INCR {diffhash2}k2), ~w(GET {diffhash1}k1)])
** (RedixCluster.Error) CROSSSLOT Keys in request don't hash to the same slot
    (redix_cluster) lib/redix_cluster.ex:215: RedixCluster.parse_error/1
Link to this function

start(type, args)
start(atom(), :permanent | :transient | :temporary) :: Supervisor.on_start()

Starts RedixCluster Application by config.exs

Link to this function

transaction(commands, opts \\ [])
transaction([command()], Keyword.t()) ::
  {:ok, [Redix.Protocol.redis_value()]} | {:error, term()}

Make sure CROSSSLOT Keys in request hash to the same slot

Examples

iex> RedixCluster.transaction([~w(set mykey 1), ~w(INCR mykey), ~w(INCR mykey), ~w(DECR mykey)])
{:ok, ["OK", "QUEUED", "QUEUED", "QUEUED", "QUEUED", ["OK", 2, 3, 2]]}

iex> RedixCluster.transaction([~w(SET {samehash}k3 foo), ~w(INCR {samehash}k2), ~w(GET {samehash}k1)])
{:ok, ["OK", "QUEUED", "QUEUED", "QUEUED", ["OK", 2, nil]]}
Link to this function

transaction!(commands, opts \\ [])
transaction!([command()], Keyword.t()) :: [Redix.Protocol.redis_value()]

Make sure CROSSSLOT Keys in request hash to the same slot

Examples

iex> RedixCluster.transaction!([~w(set mykey 1), ~w(INCR mykey), ~w(INCR mykey), ~w(DECR mykey)])
{:ok, ["OK", "QUEUED", "QUEUED", "QUEUED", "QUEUED", ["OK", 2, 3, 2]]}

iex> RedixCluster.transaction!([~w(SET {samehash}k3 foo), ~w(INCR {samehash}k2), ~w(GET {samehash}k1)])
{:ok, ["OK", "QUEUED", "QUEUED", "QUEUED", ["OK", 2, nil]]}

iex> RedixCluster.transaction!([~w(SET {diffhash3}k3 foo), ~w(INCR {diffhash2}k2), ~w(GET {diffhash1}k1)])
** (RedixCluster.Error) CROSSSLOT Keys in request don't hash to the same slot
    (redix_cluster) lib/redix_cluster.ex:215: RedixCluster.parse_error/1