mini_redis
MiniRedis
A light-weight Redis client for Crystal.
Supporters
Thanks to all my patrons, I can build and support beautiful Open Source Software! 🙏
Lauri Jutila, Alexander Maslov, Dainel Vera
You can become a patron too in exchange of prioritized support and other perks
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
- Add the dependency to your
shard.yml
:
dependencies:
mini_redis:
github: vladfaust/mini_redis
version: ~> 0.1.0
- 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
- Fork it (https://github.com/vladfaust/mini_redis/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'feat: new feature'
) using angular-style commits - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Vlad Faust - creator and maintainer