box-o-sand/redis/with-ruby/in-and-out.rb

39 lines
639 B
Ruby
Raw Normal View History

2012-02-28 06:26:08 +00:00
require 'redis/connection/hiredis'
require 'redis'
require 'pp'
2012-02-28 06:26:08 +00:00
require 'yaml'
class Fancy
attr_accessor :has_pants, :likes_to_dance
def initialize(has_pants)
@has_pants = has_pants
@likes_to_dance = true
end
end
def main
redis = Redis.new
inst = Fancy.new('yup!')
2012-02-29 04:39:35 +00:00
['foo', 'derp', 'hamsters'].each { |k| redis.del(k) }
2012-02-28 06:26:08 +00:00
puts redis.set('foo', 'bar')
puts redis.set('derp', inst.to_yaml)
puts redis.sadd('hamsters', 'albert')
puts redis.sadd('hamsters', 'walter')
puts redis.get('foo')
pp YAML.load_documents(redis.get('derp'))[0]
puts redis.smembers('hamsters')
2012-02-28 06:26:08 +00:00
end
if $0 == __FILE__
main
end