Project

kt

0.0
No commit activity in last 3 years
No release in over 3 years
Kyoto Tycoon client
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 0.10
~> 3.4

Runtime

~> 0.51.0
 Project Readme

kt-ruby

Build Status

Ruby client for Kyoto Tycoon. It uses a connection pool to maintain multiple connections.

Installation

Add this to your application's Gemfile:

gem 'kt'

Usage

require "kt"

kt = KT.new(host: "127.0.0.1", port: 1978, poolsize: 5, timeout: 5.0)

# Setting
kt.set("japan", "tokyo") # set a key
kt.set("japan", "tokyo", expire: 60) # set a key with expire of 60 seconds
kt.set_bulk({"china" => "beijing", "france" => "paris", "uk" => "london"})

kt.get("japan") # => "tokyo"
kt.get_bulk(["japan", "france"]) # => {"japan" => "tokyo", "france" => "paris"}
kt.get("foo") # => nil
kt.get!("foo") # => raises KT::RecordNotFound

kt.remove("japan") # => true
kt.remove("japan") # => false, key japan is not found anymore
kt.remove!("japan") # => raises KT::RecordNotFound becouse key japan is not found
kt.remove_bulk(["japan", "china"]) # => 1 (number keys deleted)

kt.clear # deletes all records in the database
kt.vacuum # triggers forced garbage collection of expired records

kt.set_bulk({"user:1" => "1", "user:2" => "2", "user:4" => "4"})
kt.match_prefix("user:") # => ["user:1", "user:2", "user:3", "user:4", "user:5"]

# Compare and swap
kt.set("user:1", "1")
kt.cas("user:1", "1", "2") # => true
kt.cas("user:1", "1", "3") # => false, previous value is "2"
kt.cas("user:1", nil, "3") # => false, record already exists with value "2"
kt.cas("user:2", nil, "1") # => true, no record exists so it was set
kt.cas("user:1", "2", nil) # => true, record is removed becouse it was present
kt.cas("user:1", "2", nil) # => false, it fails becouse no record with this key exists

# cas! raises where cas returns false
kt.cas!("user:1", "1", "2") # => KT::CASFailed, no record exists with this value

kt.count # => 2 keys in database

TODO

  • implement expiration for most commands
  • work with multiple servers

Contributing

  1. Fork it ( https://github.com/kuende/kt-ruby/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request