Redis client for Elixir
Add this to the dependencies:
# edge
{ :exredis, "0.0.2", [ github: "artemeff/exredis" ] }
# stable
{ :exredis, "0.0.1", [ github: "artemeff/exredis", tag: "0.0.1" ] }
As mixin
defmodule Pi do
use Exredis
def get, do: start |> query ["GET", "Pi"]
def set, do: start |> query ["SET", "Pi", "3.14"]
end
Pi.set
# => "OK"
Pi.get
# => "3.14"
Connect to the Redis server
client = Exredis.start
Set & Get
# set
Exredis.query(client, ["SET", "FOO", "BAR"])
# get
Exredis.query(client, ["GET", "FOO"])
# => "BAR"
Mset & Mget
# mset
Exredis.query(client, ["MSET" | ["key1", "value1", "key2", "value2", "key3", "value3"]])
# mget
Exredis.query(client, ["MGET" | ["key1", "key2", "key3"]])
# => ["value1","value2","value3"]
Transactions
# start
Exredis.query(client, ["MULTI"])
# exec
Exredis.query(client, ["SET", "foo", "bar"])
Exredis.query(client, ["SET", "bar", "baz"])
# commit
Exredis.query(client, ["EXEC"])
Pipelining
Exredis.query_pipe(client, [["SET", :a, "1"], ["LPUSH", :b, "3"], ["LPUSH", :b, "2"]])
Pub/sub (maybe won't work)
Exredis.subscribe(client, "foo")
Exredis.publish(client, "foo", "bar")
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request