Skip to content

Instantly share code, notes, and snippets.

@burke
Created July 30, 2011 22:52
Show Gist options
  • Save burke/1116111 to your computer and use it in GitHub Desktop.
Save burke/1116111 to your computer and use it in GitHub Desktop.
require 'redis'
require 'msgpack'
class ObjectDB
def initialize(*redis_args)
@connection = Redis.connect(*redis_args)
end
def get(key)
serialized = @connection.get(key)
serialized ? MessagePack.unpack(serialized) : nil
end
def set(key, obj)
@connection.set(key, obj.to_msgpack)
end
end
if __FILE__ == $0
x=ObjectDB.new
x.set("k", {"a" => "b"})
puts "OK" if ({"a" => "b"}) == x.get("k")
# require 'benchmark'
#
# puts Benchmark.realtime {
# obj = {3 => 2}
# 100_000.times {
# x.set("k", obj)
# x.get("k")
# }
# }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment