ex_redi

A simple Elixir client for RediSearch


Keywords
elixir, redis, redisearch, search
License
MIT

Documentation

ExRedi

A simple Elixir client for RediSearch

Hex.pm Hex.pm

Installation

def deps do
  [
    {:ex_redi, "~> 0.1.0"}
  ]
end

Usage

Create/Drop an index

iex> ExRedi.create("myIdx", ["player", "TEXT", "games", "NUMERIC", "SORTABLE"])
:ok

iex> ExRedi.drop("myIdx")
:ok

Add some documents

iex> ExRedi.add("myIdx", "1", ["player", "foo", "games", 5])
:ok

iex> docs = [
...>   {"2", ["player", "bar", "games", 8]},
...>   {"3", ["player", "baz", "games", 4]}
...> ]
...> ExRedi.add_multi("myIdx", docs)
[:ok, :ok]

Find some documents

iex> ExRedi.search("myIdx", "foo")
{:ok, [%{"games" => "5", "id" => "1", "player" => "foo"}]}

iex> ExRedi.search("myIdx", "nothing")
{:ok, []}

iex> ExRedi.search("myIdx", "@games:[3 5]")
{:ok, [
  %{"games" => "4", "id" => "3", "name" => "baz"},
  %{"games" => "5", "id" => "1", "name" => "foo"}
]}

Get a specific document

iex> ExRedi.get("myIdx", "2")
{:ok, %{"games" => "8", "id" => "2", "player" => "bar"}}

iex> ExRedi.get("myIdx", "not-a-doc")
{:ok, nil}

Remove a document from the index

iex> ExRedi.del("myIdx", "3")
{:ok, 1}

Redis Configuration

ExRedis uses Redix to manage Redis connections. All Redix options are easily configurable:

config :ex_redi,
  redix_behaviour: [
    password: "secret",
    database: 3
  ],
  redix_connection: [
    sync_connect: true
  ]