crystal-redis

玄學醬發表於2018-03-01

A Redis client for the Crystal programming language.

Features

  • Performance (> 680,000 commands per second using pipeline on a MacBook Air with a single client thread)
  • Pipelining
  • Transactions
  • LUA Scripting
  • All string commands
  • All hash commands
  • All list commands
  • All set commands
  • All hyperloglog commands
  • All commands for bit operations
  • All sorted set commands
  • Publish/subscribe

Installation

Add it to your shard.yml:

dependencies:
  redis:
    github: stefanwille/crystal-redis
    version: ~> 1.9.0

and then install the library into your project:

$ crystal deps

Required Crystal Version

This library needs Crystal version >= 0.18.2

Usage

Require the package:

  require "redis"

then

  redis = Redis.new

Then you can call Redis commands on the redis object:

  redis.set("foo", "bar")
  redis.get("foo")

Examples

To get started, see the examples:

  • There is a separate git repository crystal-redis-examples with examples.
  • start with this basic example
  • look at the other examples
  • the spec contains even more usage examples

Documentation

  • API documentation – start reading it at the class Redis.
  • Redis commands documentation – the original Redis documentation is necessary, as the API documentation above is just a quick reference
  • Redis documentation page – general information about Redis and its concepts

Performance

I have benchmarked Crystal-Redis against several other client libraries in various programming languages in this blog article.

Here are some results:

  • Crystal: With this library I get > 680,000 commands per second using pipeline on a MacBook Air with a single client thread.

  • C: The equivalent program written in C with Hiredis gets me 340,000 commands per second.

  • Ruby: Ruby 2.2.1 with the redis-rb and Hiredis driver handles 150,000 commands per second.

Read more results for Go, Java, Node.js.

Status

I have exercised every API method in the spec and built some example programs. There is no production use yet.

I took great care to make this library very usable with respect to API, reliability and documentation.

Development

This project requires a locally running redis server running on port 6379 and with a unix socket located at /tmp/redis.sock. Then you can the specs via

$ crystal spec

See more information.

Questions, Bugs & Support

If you have questions or need help, please open a ticket in the GitHub issue tracker. This way others can benefit from the discussion.

本文作者:陳群
本文來自雲棲社群合作伙伴rediscn,瞭解相關資訊可以關注redis.cn網站。