Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



38 Commits

Repository files navigation


Built with Crystal Build status API Docs Releases Awesome Patrons count Gitter chat

A light-weight Redis client for Crystal.

Become Patron


MiniRedis is a light-weight low-level alternative to existing Redis client implementations.

In comparison with crystal-redis, MiniRedis has lesser memory consumption, built-in logging and first-class support for raw bytes. It also doesn't need to be updated with every Redis release.

On the other hand, MiniRedis doesn't have commands API (i.e. instead of you should write redis.send("PING")). However, such a low-level interface terminates the dependency on the third-party client maintainer (i.e. me), which makes it a perfect fit to use within a shard.

You can always find the actual Redis commands API at


Benchmarks code can be found at These are recent results of comparison MiniRedis with crystal-redis.

send benchmarks

> env REDIS_URL=redis://localhost:6379/1 crystal src/ --release
mini_redis     13.4k ( 74.62µs) (± 2.50%)   32 B/op        fastest
crystal-redis  13.36k ( 74.83µs) (± 2.97%)  144 B/op   1.00× slower

Conclusion: mini_redis is more memory-efficient.

Pipeline mode benchmarks

1 million pipelined sends, average from 30 times repeats:

> env REDIS_URL=redis://localhost:6379/1 crystal src/ --release
mini_redis    914.569ms 1.093M ops/s
crystal-redis 908.182ms 1.101M ops/s

Conclusion: mini_redis has almost the same speed as crystal-redis.


  1. Add the dependency to your shard.yml:
    github: vladfaust/mini_redis
    version: ~> 0.2.0
  1. Run shards install

This shard follows Semantic Versioning v2.0.0, so check releases and change the version accordingly. Note that until Crystal is officially released, this shard would be in beta state (0.*.*), with every minor release considered breaking. For example, is breaking and is not.


require "mini_redis"

redis =

# MiniRedis responses wrap `Int64 | String | Bytes | Nil | Array(Value)` values,
# which map to `Integer`, `Simple String`, `Bulk String`, `Nil` and `Array` Redis values

# SET command returns `Simple String`, which is `String` in Crystal
pp redis.send("SET", "foo", "bar") # => "OK"

# GET command returns `Bulk String`, which is `Bytes` in Crystal
bytes = redis.send("GET", "foo")
pp # => "bar"

# Bytes command payloads are also supported
redis.send("set", "foo".to_slice, "bar".to_slice)


response = redis.pipeline do |pipe|
  # WARNING: Accessing the `.send` return value
  # within the pipe block would crash the program!
  pipe.send("SET", "foo", "bar")

pp typeof(response) # => [MiniRedis::Value(@raw="OK")]


response = redis.transaction do |tx|
  pp tx.send("SET", "foo", "bar") # => "QUEUED"

pp typeof(response) # => MiniRedis::Value(@raw=[MiniRedis::Value(@raw="OK")])

Connection pool

pool =

response = pool.get do |redis|
  # Redis is MiniRedis instance, can do anything

# Return value equals to the block's
pp # => "PONG"

conn = pool.get
pp conn.send("PING") # => "PONG"
pool.release(conn) # Do not forget to put it back!


env REDIS_URL=redis://localhost:6379 crystal spec and you're good to go.


  1. Fork it (
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'feat: new feature') using angular-style commits
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request