-
-
Save workmad3/7033283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RiakWrapper | |
def initialize | |
walk_server = WalkServer.first | |
@client = Riak::Client.new(:protocol => "pbc", :host => walk_server.host, :pb_port => walk_server.pb_port) | |
end | |
def exists?(key, bucket_name) | |
bucket(bucket_name).exists?(key) | |
end | |
def get(key, bucket_name) | |
bucket(bucket_name).get(key) | |
end | |
def delete(key, bucket_name) | |
bucket(bucket_name).delete(key) if exists?(key, bucket_name) | |
end | |
def bucket(bucket_name) | |
@client.bucket(bucket_name) | |
end | |
def self.current | |
Thread.local[:current_riak_wrapper] ||= new | |
end | |
def self.reset | |
Thread.local[:current_riak_wrapper] = nil | |
end | |
end | |
# USAGE EXAMPLE | |
RiakWrapper.current.delete("#dg_123456", 'terminals') | |
RiakWrapper.current.exists?("bm_654321.dat", 'files') | |
RiakWrapper.current.get("ig_13579.xml", 'files') | |
# REAL USE | |
RiakWrapper.current.delete("#{acronym}_#{self.number}", 'terminals') | |
RiakWrapper.current.delete("#{acronym}_#{self.number}_params.dat", 'assets') | |
RiakWrapper.current.delete("#{acronym}_#{self.number}_params.dat", 'files') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment