また、Nestのようなものを使用して、鍵を乾燥させることもできます。
addresses = Nest.new("Address", Redis.new)
this_address = addresses[1]
# => "Address:1"
this_address.hset(:name, "foo")
this_address.hset(:street, "bar")
this_address.hgetall
# => {"name" => "foo", "street" => "bar"}
より高度なものが必要な場合は、Ruby クラスを Redis にマップするOhmがあります。
class Address < Ohm::Model
attribute :name
attribute :street
attribute :number
end
# Create
Address.create(:name => "foo", :street => "bar")
# Find by ID
Address[1]
# Find all addresses with name "foo"
class Address < Ohm::Model
attribute :name
attribute :street
attribute :number
index :name
end
Address.find(:name => "foo")
# => Array-like with all the Address objects