Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A lightweight, flexible key generator for NoSQL / Key-Value stores, such as Redis, Memcached, Riak, Tokyo Cabinet, etc.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
README.rdoc
  /~\
 C oo
 _( ^)  kiki
/   ~\

A lightweight, flexible key generator for NoSQL / Key-Value stores, such as Redis, Memcached, Riak, Tokyo Cabinet, etc.

Installation

$ gem install kiki

Examples

class User
  include Kiki

  cache_key :redis

  cache_key :memcached,
            :domain     => 'people',
            :delimiter  => '/',
            :identifier => :username
end

User.redis_key                  # => #<Keytar::Key:0x000001008ea9a8 @namespace="redis", @delimitter=":", @domain="users", @identifier=:id>
User.redis_key("count")         # => redis:users:count
User.find(1).redis_key          # => redis:users:1
User.find(1).redis_key("items") # => redis:users:1:items

User.find(1).memcached_key      # => memcached/people/schneems

# Configuration can be done on the key object
User.memcached_key.identifier = :email
User.find(1).memcached_key      # => memcached/people/mistersnowman@example.com

Configuration

namespace

the first argument for cache_key, the instance and class method +[namespace]_key+ will be added, which generate keys prefixed by the namespace (eg. “redis” would add the method “redis_key”, generating a key like “redis:users:1”)

domain

optional, defaults to the downcase, pluralized name of your class (eg. “class User” would have the domain “users”)

delimiter

optional, defaults to “:”

identifier

this is the method that is sent when calling “*_key” on an instance, or passing non-string / non-numeric arguments into a “*_key” method. optional, defaults to “:id”

Credit

This project was inspired by Richard Schneeman's awesome library Keytar (github.com/schneems/keytar). Essentially, this my alternative take on the problem, focusing on simplicity of API and implementation.

License

kiki is licensed under the MIT License:

Copyright © 2011 Mattt Thompson (mattt.me)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.