Created
July 30, 2011 22:52
-
-
Save burke/1116111 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
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