Skip to content

Instantly share code, notes, and snippets.

@adamhunter
Created June 20, 2011 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamhunter/1035927 to your computer and use it in GitHub Desktop.
Save adamhunter/1035927 to your computer and use it in GitHub Desktop.
basic read write cache for riak
require 'riak'
class RiakCache
def initialize
@client = Riak::Client.new(:pb_port => 8081, :protocol => :pbc)
@bucket = @client.bucket("riakcache")
end
def read(key)
@object = @bucket.get(key)
@object.data
end
def write(key, value)
@object = @bucket.get_or_new(key)
@object.content_type = 'application/x-ruby-marshal'
@object.data = value
@object.store
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment