igrigorik / tokyo-recipes

Lean & mean Tokyo Cabinet recipes (with Lua)

This URL has Read+Write access

igrigorik (author)
Fri Jul 10 14:03:18 -0700 2009
commit  1fdaf47a1fcf7a77e721379b1efa9cc0a510f72f
tree    07fb4b09ad70f2428769a4079c7916db8ebc76f8
parent  cec510f5419793e3331c5dd97487764133e6e79e
tokyo-recipes / expire
name age message
..
file README.rdoc Loading commit data...
file expire.lua
file expire.rb
expire/README.rdoc

Auto record expire based on TTL

Implements TTL-based record expiry via a Lua script which is periodically executed by the TC runtime.

  • The calling period is customizable via -extpc flag
  • Data is stored inside a ‘table’ engine where key ‘x’ stores the unix timestamp for the expiry date
  • Lua cleanup script is called periodically to scan the database for keys ready to be removed, which are then purged from the DB.

Starting server

  # call expire script every 5 seconds
  > ttserver -ext expire.lua -extpc expire 5 "casket.tct#idx=x:dec#bnum=2000000"

Executing via Ruby

  > ruby expire.rb
  > nil
  > {"name"=>"bob", "x"=>"1247025691"}