Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Abuse Sql database as Key-Value Store

tag: v0.4.1

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 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 Rakefile
Octocat-spinner-32 Readme.md
Octocat-spinner-32 VERSION
Octocat-spinner-32 key_value.gemspec
Readme.md

Abuse Sql database as Key-Value Store that can be 750k-qps-crazy-fast via HandlerSocket

Install

sudo gem install key_value

Migration

rails g migration create_key_value and paste in:

class CreateKeyValue < ActiveRecord::Migration
  def self.up
    create_table :key_values do |t|
      t.string :key, :null => false
      t.text :value, :null => false
    end
    add_index :key_values, :key, :unique => true
  end

  def self.down
    drop_table :key_values
  end
end

Usage

# get
KeyValue['xxx'] -> {:baz=>'foo'}
or KeyValue.get('xxx') -> {:baz=>'foo'}

# set
KeyValue['xxx'] = {:baz=>'foo'})
or KeyValue.set('xxx', {:baz=>'foo'})

# delete
KeyValue['xxx'] = nil
or KeyValue.del('xxx')

# increment
KeyValue.inc('xxx') # !! Not atomic
or KeyValue.inc('xxx', 5)

# cache
KeyValue.cache('xxx'){ ..something expensive.. }

HandlerSocket (Ubuntu natty guide):

KeyValue.handler_socket = true
# or Hash with any of these keys :host :port :database :timeout :listen_backlog :sndbuf :rcvbuf

# all read requests use HandlerSocket
KeyValue['xxx'] # -> same as before but faster :)

TODO

  • HandlerSocket write support
  • make test database configurable

Authors

Roman Heinrich
Michael Grosser
Hereby placed under public domain, do what you want, just do not hold anyone accountable...

Something went wrong with that request. Please try again.