Tokyo Cabinet

Posts tagged with "Tokyo Cabinet."
  • 10


    Tokyo Cabinet's Key-Value Database Types

    We've taken a good look at Tokyo Cabinet's Hash Database, but there's a lot more to the library than just that. Tokyo Cabinet supports three other kinds of databases. In addition, each database type accepts various tuning parameters that can be used to change its behavior. Each database type and setting involves different tradeoffs so you really have a lot of options for turning Tokyo Cabinet into exactly what you need. Let's look into some of those options now.

    The B+Tree Database

    Tokyo Cabinet's B+Tree Database is a little slower than the Hash Database we looked at before. That's its downside. However, giving up a little speed gains you several extra features that may just allow you to work smarter instead of faster.

    The B+Tree Database is a more advanced form of the Hash Database. What that means is that all of the stuff I showed you in the last article still applies. You can set, read, and remove values by keys, iteration is supported, and you still have access to the neat options like adding to counters. With a B+Tree Database you get all of that and more.

    Read more…

  • 1


    Tokyo Cabinet as a Key-Value Store

    Like most key-value stores, Tokyo Cabinet has a very Hash-like interface from Ruby (assuming you use Oklahoma Mixer). You can almost think of a Tokyo Cabinet database as a Hash that just happens to be stored in a file instead of memory. The advantage of that is that your data doesn't have to fit into memory. Luckily, you don't have to pay a big speed penalty to get this disk-backed storage. Tokyo Cabinet is pretty darn fast.

    Getting and Setting Keys

    Let's have a look at the normal Hash-like methods as well as the file storage aspect:

    #!/usr/bin/env ruby -KU
    require "oklahoma_mixer""data.tch") do |db|
        puts "Loading the database.  Rerun to read back the data."
        db[:one] = 1
        db[:two] = 2
        db.update(:three => 3, :four => 4)
        db["users:1"] = "James"
        db["users:2"] = "Ruby"
        puts "Reading data."
        %w[ db[:one]
            db.keys(:prefix\ =>\ "users:")
            db.keys(:limit\ =>\ 2)
            db.values_at(:one,\ :two) ].each do |command|
          puts(command == "-" ? "" : "#{command} = %p" % [eval(command)])

    Read more…

  • 14


    Using Key-Value Stores From Ruby

    I've been playing with a few different key-value stores recently. My choices are pretty popular and you can find documentation for them. However, it can still be a bit of work to relate everything to Ruby specific usage, which is what I care about. Given that, here are my notes on the systems I've used.


    1. Setting up the Redis Server
    2. Using Redis as a Key-Value Store
    3. Lists and Sets in Redis
    4. Where Redis is a Good Fit

    Tokyo Cabinet, Tokyo Tyrant, and Tokyo Dystopia

    1. Installing the Tokyo Software
    2. Tokyo Cabinet as a Key-Value Store
    3. Tokyo Cabinet's Key-Value Database Types
    4. Tokyo Cabinet's Tables
    5. Threads and Multiprocessing With Tokyo Cabinet
    6. Tokyo Tyrant as a Network Interface
    7. The Strengths of Tokyo Cabinet