README.md

# ExRedi

A simple Elixir client for [RediSearch](http://redisearch.io/)

[![Build Status](https://travis-ci.org/l1h3r/ex_redi.svg?branch=master)](https://travis-ci.org/l1h3r/ex_redi)
[![Coverage Status](https://coveralls.io/repos/github/l1h3r/ex_redi/badge.svg?branch=master)](https://coveralls.io/github/l1h3r/ex_redi?branch=master)
[![Hex.pm](https://img.shields.io/hexpm/v/ex_redi.svg?style=flat-square)](https://hex.pm/packages/ex_redi)
[![Hex.pm](https://img.shields.io/hexpm/dt/ex_redi.svg?style=flat-square)](https://hex.pm/packages/ex_redi)

## Installation

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

## Usage

Create/Drop an index

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

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

Add some documents

```elixir
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

```elixir
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

```elixir
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

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

## Redis Configuration

ExRedis uses [Redix](https://hex.pm/packages/redix) to manage Redis connections. All Redix options are easily configurable:

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