Home

Awesome

Kiwi

Build Status

A simple unified Crystal interface for key-value stores.

Installation

Add this to your application's shard.yml:

dependencies:
  kiwi:
    github: crystal-community/kiwi
    version: ~> 0.1.0

Usage

All the stores have the same simple interface defined by Kiwi::Store:

MemoryStore

require "kiwi/memory_store"

store = Kiwi::MemoryStore.new

store.set("key", "value")
store.get("key")  # => "value"
store.delete("key")
store.clear

# Or your can use Hash-like methods:
store["key"] = "new value"
store["key"]  # => "new "value"

FileStore

require "kiwi/file_store"

store = Kiwi::FileStore("/tmp/kiwi")

RedisStore

RedisStore requires you to have redis shard.

require "redis"
require "kiwi/redis_store"

store = Kiwi::RedisStore(Redis.new)

LevelDBStore

LevelDBStore requires you to have levelDB shard.

require "leveldb"
require "kiwi/leveldb_store"

leveldb = LevelDB::DB.new("./db")
store = Kiwi::LevelDBStore(leveldb)

MemcachedStore

MemcachedStore requires you to have memcached shard.

require "memcached"
require "kiwi/memcached_store"

store = Kiwi::MemcachedStore.new(Memcached::Client.new)

Benchmark

The following table shows operations per second for every particular store on my machine.

setgetget(empty)delete
MemoryStore30560004166000407400010473000
LevelDBStore12000019300025300037000
RedisStore41000420004200021000
MemcachedStore38000410004000021000
FileStore2700066000730008000

Data information:

Environment information:

Results can vary on different systems depending on hardware(CPU, RAM, HDD/SSD) and software(OS, file system, etc).

Running benchmark

make benchmark

Tests

Run specs for all stores:

make test

Run spec for a particular store:

crystal spec ./spec/kiwi/file_store_spec.cr

Contributors