• Stars
    star
    8
  • Rank 2,099,232 (Top 42 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 10 years ago
  • Updated almost 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Yet another Redis client for Elixir

YAR

Yet Another Redis client for Elixir

YAR is a Redis client written in Elixir. It is not a wrapper around the excellent Erlang client eredis, it is implemented from scratch in Elixir using elixir-socket (which is itself a wrapper around Erlang's gen_tcp) for TCP/IP communication.

This project is probably not ready for production, though I would greatly appreciate any feedback and bug reports.

If you are looking for a solid Elixir Redis client, check out exredis. exredis is a wrapper around eredis, which is an Erlang Redis client that has been around for quite some time.

##Usage

Create a new Redis connection process with YAR.connect/2 and then use YAR.execute/2 to execute raw Redis commands.

{:ok, redis} = YAR.connect("localhost", 6379)
"PONG" = YAR.execute(redis, "PING")
"OK" = YAR.execute(redis, "SET FOO 1")
2 = YAR.execute(redis, "INCR FOO")
"2" = YAR.execute(redis, "GET FOO")
"OK" = YAR.execute(redis, "SET BAR BAZ")
"OK" = YAR.execute(redis, ["SET", "BAR", "BAZ"])
["2", "BAZ"] = YAR.execute(redis, "MGET FOO BAR")
{:error, "unknown command 'SUP'"} = YAR.execute(redis, "SUP")

YAR.connect/2 takes host and port as arguments, with default values of "localhost" and 6379. {:ok, redis} = Yar.connect should connect to a default local instance of redis-server on most installations. Multiple connections can be made by simply calling Yar.connect/2 multiple times.

In theory, YAR supports arbitrary Redis commands via YAR.execute/2. All of the basic return types should be supported.

YAR.execute/2 is synchronous. The underlying connection uses elixir-socket and stores the connection information in a GenServer.

The list form of execute should be favored for performance reasons. That is, YAR.execute(redis, ["GET", "FOO"]) is slightly more performant than YAR.execute(redis, "GET FOO").

##Helpers

YAR has built-in helpers for some Redis commands.

"OK" == YAR.set(c, "foo", "bar")
"bar" == YAR.get(c, "foo")
# note keys/values are interleaved
"OK" == YAR.mset(c, ["foo", 1, "bar", 2])
["1", "2"] == YAR.mget(c, ["foo"], ["bar"])

##Pipelining

YAR supports simple Redis pipelining via YAR.pipeline/2. The second argument is a list of commands. The responses are returned as a list in order corresponding to the commands.

["OK", "PING"] == YAR.pipeline(redis, [["SET", "FOO", "42"], ["PING"]])
["42", "OK"] == YAR.pipeline(redis, [["GET", "FOO"], ["SET", "FOO", "1"]])

##Pubsub

YAR supports simple Redis subscribing via YAR.subscribe/4. The first argument is a pid to receive messages, the second argument is a list of routing keys, the third and fourth arguments are the Redis host and port, respectively (default "localhost" and 5379). Messages are delivered as tuples where the first element is :yarsub and the second argument is the message string.

{:ok, subscriber_pid} = YAR.subscribe(self, ["foo"])
YAR.execute(redis, ["PUBLISH", "foo", "hullo"])
flush # => {:yarsub, "hullo"}

##Testing

Launch a Redis server instance on port 5000 (redis-server -- port 5000) then run mix test.

CAUTION - The test executes FLUSHALL between test cases. DO NOT test on a production server! If you must, take care that no data is kept on a Redis instance on port 5000, or change the test port in test/yar_test.exs.

More Repositories

1

redis-matlab

A Redis client in pure Matlab
MATLAB
23
star
2

mix_eunit

A mix task to execute eunit tests.
Elixir
17
star
3

thrash

Fast, idiomatic Elixir library for Apache Thrift serialization and deserialization
Elixir
12
star
4

patiently

Helpers for waiting on asynchronous events
Elixir
11
star
5

thrift_ex

Elixir package for Apache Thrift
Elixir
8
star
6

kafka_ex_examples

Examples using KafkaEx
Elixir
7
star
7

rabbitmq_ha_federation

RabbitMQ Federation + HA queue proof of concept / experiment
Python
5
star
8

ruby-c-extensions

Code and documentation surrounding my upcoming talk at Fort Worth Ruby Brigade. *gulp*
C
5
star
9

ambient_wx_exporter

Prometheus exporter for Ambient Weather personal weather station (PWS) data
Go
3
star
10

calculon

Example app for integration testing in Phoenix
Elixir
3
star
11

tail_f

Elixir implementation of `tail -F`.
Elixir
3
star
12

RspecHasMany

Minimal example showing the problem here: http://stackoverflow.com/questions/8914121/rspec-testing-has-many-through-and-after-save
Ruby
2
star
13

beanie

Docker registry web viewer powered by Elixir & Phoenix
Elixir
2
star
14

phoenix_presence_chat

Demo Phoenix app using Presence to track online status
Elixir
2
star
15

slobber

slobber is a slaver for OS X Terminal.app windows
Ruby
1
star
16

m-files

A collection of useful Matlab m-files that I have accumulated over the years.
MATLAB
1
star
17

BelugaIPC

IPC Server for the Beluga project
MATLAB
1
star
18

RecordModel

RecordModel
C++
1
star
19

etoma

Erlang automata playground with websocket-driven visualization
JavaScript
1
star
20

StaticConstUndefinedSymbol

A couple minimal examples of a c++ quirk that I've been trying to understand.
C++
1
star
21

RTunes

Thin wrapper for controlling iTunes from Ruby on OS X.
Ruby
1
star
22

rhubarb

A lightweight and extensible IPC server. The server is written in ruby, clients can be written in any language with socket support.
Ruby
1
star
23

compositer

A simple video frame compositer.
C++
1
star
24

tenfour

Simple site status monitor using cron
Ruby
1
star
25

tailor

A tool for analyzing Slack exports, except not really.
Jupyter Notebook
1
star
26

brief-tour-of-elixir

"A Brief Tour of Elixir" talk and sample code
Elixir
1
star
27

sir_yes_sir

SIR model Jupyter notebooks
Jupyter Notebook
1
star
28

cpp-for-engineers

A consise c++ tutorial for engineers (or anyone, really) that already know some programming.
C++
1
star