mini_redis

A light-weight low-level Redis client redis
0.1.0 released
vladfaust/mini_redis
17 2 7
Vlad Faust

MiniRedis

Built with Crystal Build status Docs Releases Awesome vladfaust.com Patrons count

A light-weight Redis client for Crystal.

Supporters

Thanks to all my patrons, I can build and support beautiful Open Source Software! 🙏

Lauri Jutila

Become Patron

About

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

In comparison with crystal-redis, MiniRedis is slightly faster, has first-class support for raw bytes and doesn't need to be updated with every Redis release. On the other hand, MiniRedis doesn't have commands API (i.e. instead of redis.ping you should write redis.command("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.

Installation

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

Usage

require "mini_redis"

redis = MiniRedis.new

# Inline (i.e. one-line) commands are usually faster, because they don't need marshalling
pp redis.command("PING").raw.as(String) # => "PONG"

# MiniRedis responses wrap `Int64 | String | Bytes | Nil | Array(Value)` values, which are
# properly mapped to `integer`, `simple string`, `bulk string`, `nil` and `array` Redis values
pp redis.command("SET foo bar").raw.as(String) # => "OK"
bytes = redis.command("GET foo").raw.as(Bytes)
pp String.new(bytes) # => "bar"

# It is possible to declare commands as enumerables (or pass as many arguments),
# so they are going to be marshalled according to the Redis protocol.
# It is particulary useful for commands with binary payloads
redis.command({"set", "foo", "bar".to_slice})
redis.command("set", "foo", "bar".to_slice)

# It is possible to split sending and receiving the response
redis.send("SET foo bar")
redis.receive

# Pipelining
response = redis.pipeline do |pipe|
  pipe.send("SET foo bar")
end

pp typeof(response) # => Array(MiniRedis::Value)

# Transactions
response = redis.transaction do |tx|
  tx.send("SET foo bar")
end

pp typeof(response) # => MiniRedis::Value

Development

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

Contributing

  1. Fork it (https://github.com/vladfaust/mini_redis/fork)
  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

Contributors

mini_redis:
  github: vladfaust/mini_redis
  version: ~> 0.1.0
License MIT
Crystal 0.27.0

Authors

Dependencies 0

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently