whoahbot/dm-redis-adapter — Issue #25: Textual Keys Fail
Author: jof
Created: 2012-01-25 00:32:00+00:00
State: open

When using non-Serial keys for models (like a Text, for example), models are able to be built and persisted just fine. However, when reading back out, the key property becomes a string "0".

Take this example program:

```ruby
jof@jof ~/tmp % cat foomodel.rb
#!/usr/bin/env ruby

require 'rubygems'
require 'dm-core'
require 'dm-redis-adapter'

DataMapper.setup(:default, :adapter => :redis)
class Foo
include DataMapper::Resource
property :hostname, Text, :key => true
property :ip_address, Text
end
DataMapper.finalize

(0..10).each do |i|
Foo.create(:hostname => "hostname#{i}", :ip_address => '127.0.0.1')
end

Foo.all.each { |f| p f.hostname }
```

Contrary to what you might expect, this prints:

```
jof@jof ~/tmp % ./foomodel.rb
"0"
"0"
"0"
"0"
"0"
"0"
"0"
"0"
"0"
"0"
"0"
```

However, the keys persisted into Redis just fine:

```
jof@jof ~ % redis-cli hgetall foo:hostname0
1) "hostname"
2) "hostname0"
3) "ip_address"
4) "127.0.0.1"
jof@jof ~ % redis-cli hgetall foo:hostname1
1) "hostname"
2) "hostname1"
3) "ip_address"
4) "127.0.0.1"
```