/redis-protocol.cr

crystal support for "redis-protocol.rb"

Primary LanguageCrystalMIT LicenseMIT

redis-protocol.cr Build Status

crystal support for "redis-protocol.rb"

TODO

  • RedisProtocol::Parse (0.1 ready)
  • RedisProtocol::Request (maybe 0.2)
  • RedisProtocol::Response (maybe 0.3)

Installation

Add this to your application's shard.yml:

dependencies:
  redis-protocol:
    github: maiha/redis-protocol.cr
    version: 0.1.1

Usage

require "redis-protocol"

parse

RESP Simple Strings

resp = RedisProtocol.parse("+OK\r\n")
p resp       # => RedisProtocol::RedisString(@raw="OK")
p resp.value # => "OK"

RESP Errors

resp = RedisProtocol.parse("-Error message\r\n")
p resp       # => RedisProtocol::RedisError(@raw="Error message")
p resp.value # => "Error message"

RESP Integers

resp = RedisProtocol.parse(":1000\r\n")
p resp       # => RedisProtocol::RedisInteger(@raw=1000)
p resp.value # => 1000

RESP BulkString

resp = RedisProtocol.parse("$6\r\nfoobar\r\n")
p resp       # => RedisProtocol::RedisString(@raw="foobar")
p resp.value # => "foobar"

RESP Null

resp = RedisProtocol.parse("$-1\r\n")
p resp       # => RedisProtocol::RedisNull()
p resp.value # => nil

RESP Array

resp = RedisProtocol.parse("*2\r\n$4\r\nkeys\r\n$1\r\n*\r\n")
p resp       # => RedisProtocol::RedisArray(@raw=[RedisProtocol::RedisString(@raw="keys"), RedisProtocol::RedisString(@raw="*")])
p resp.value # => ["keys", "*"]

Development

Contributing

  1. Fork it ( https://github.com/maiha/redis-protocol.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors