Sha256: 46c30a2c84d92893d1f86e6107dafea2ba7d2f4734e1655d8a21b632916c609e

Contents?: true

Size: 909 Bytes

Versions: 1

Compression:

Stored size: 909 Bytes

Contents

require 'rufus/tokyo/tyrant'

module CurlyMustache
  module Adapters
    class TokyoTyrant < Abstract
      
      def initialize(config)
        config = config.reverse_merge :server => "localhost", :port => 1978
        @db = Rufus::Tokyo::Tyrant.new(config[:server], config[:port])
      end
      
      def get(key)
        (data = @db[key]) and Marshal.load(data)
      end
      
      def mget(keys)
        keys = keys.collect(&:to_s)
        results = @db.lget(keys)
        keys.inject([]) do |memo, key|
          data = results[key]
          memo << Marshal.load(data) if data
          memo
        end
      end
      
      def put(key, value)
        @db[key] = Marshal.dump(value)
      end
      
      def delete(key)
        @db.delete(key) ? true : false
      end
      
      def flush_db
        @db.clear
      end
      
      def raw
        @db
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cjbottaro-curly_mustache-0.0.0 lib/adapters/tokyo_tyrant.rb