Skip to content

roryqueue/fakeredis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Hex.pm

FakeRedis

FakeRedis recreates the Redis API using only native Erlang/Elixir features, especially ETS.

This package recreates the Redis API for development and testing purposes, ignoring thread safety and using Erlang Term Storage and no outside dependencies. This can be useful in development and testing environments because it removes the dependency on an actual Redis instance.

Usage

Commands can be used either through command/2 or as functions. Per elixir standard, functions ending in a bang (!) will throw an exception if something goes wrong, while those without will return standard :ok/:error format:

Command behavior matches the Redis command API, using elixir list, map, and bitstring types to replace the Redis array, hash, and string types respectively.

  1. Using named command functions without bang:
iex(1)> {status, result} = FakeRedis.set(connection, ["key", "value"])
{:ok, "OK"}
iex(1)> {status, result} = FakeRedis.get(connection, "key")
{:ok, "value"}
  1. Using named command functions with bang:
iex(1)> result = FakeRedis.set!(connection, ["key", "value"])
"OK"
iex(1)> result = FakeRedis.get!(connection, "key")
"value"
  1. Using command/2 (without bang):
iex(1)> {status, result} = FakeRedis.command(connection, ~w(SET key value))
{:ok, "OK"}
iex(1)> {status, result} = FakeRedis.command(connection, ~w(GET key value))
{:ok, "value"}
  1. Using command!/2 (with bang):
iex(1)> result = FakeRedis.command!(connection, ~w(SET key value))
"OK"
iex(1)> result = FakeRedis.command!(connection, ~w(GET key value))
"value"

Supported commands are keys, set, setnx, setex, psetex, mset, msetnx, get, getset, mget, expire, expireat, pexpire, pexpireat, ttl, pttl, exists, del, persist, incr, incrby, decr, decrby, strlen, append, getrange, setrange, hget, hgetall, hmget, hkeys, hvals, hexists, hlen, hdel, hset, hsetnx, hincrby, lpushall, lpush, lpushx, rpush, rpushx, llen, lpop, rpop, rpoplpush, lset, lindex, linsert, ltrim, lrem.

Installation

This package can be installed as:

  1. Add fakeredis to your list of dependencies in mix.exs:
def deps do
  [{:fakeredis, "~> 0.2.0"}]
end
  1. Ensure fakeredis is started before your application:
def application do
  [applications: [:fakeredis]]
end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages