dm-redis-adapter 0.8.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +1 -0
- data/lib/dm-redis-adapter/adapter.rb +3 -3
- data/spec/composite_keys_spec.rb +53 -0
- metadata +3 -2
data/README.textile
CHANGED
@@ -14,6 +14,7 @@ Please note that as of version 0.5.3 of the gem, the key names that are used for
|
|
14
14
|
|
15
15
|
h1. Changelog
|
16
16
|
|
17
|
+
* v0.9.0 Fixes for composite keys being indexed (thanks @fringley)
|
17
18
|
* v0.8.4 Fixes for composite keys (thanks @krider2010)
|
18
19
|
* v0.8.2 Updates to RedisAdapter#initialize to support URI. (thanks @thentenaar)
|
19
20
|
* v0.8.1 Dependency updates by @jof to support newer versions of the redis gem.
|
@@ -117,7 +117,7 @@ module DataMapper
|
|
117
117
|
attributes = resource.dirty_attributes
|
118
118
|
|
119
119
|
resource.model.properties.select {|p| p.index}.each do |property|
|
120
|
-
@redis.sadd("#{storage_name}:#{property.name}:#{encode(resource[property.name.to_s])}", resource.key.
|
120
|
+
@redis.sadd("#{storage_name}:#{property.name}:#{encode(resource[property.name.to_s])}", resource.key.join.to_s)
|
121
121
|
end
|
122
122
|
|
123
123
|
properties_to_set = []
|
@@ -147,7 +147,7 @@ module DataMapper
|
|
147
147
|
|
148
148
|
def key_query(query)
|
149
149
|
matched_records = []
|
150
|
-
value =""
|
150
|
+
value = ""
|
151
151
|
storage_name = query.model.storage_name
|
152
152
|
query.conditions.operands.each do |operand|
|
153
153
|
value += operand.value.to_s if operand.subject.key?
|
@@ -221,7 +221,7 @@ module DataMapper
|
|
221
221
|
# Find records that match have a matching value
|
222
222
|
#
|
223
223
|
# @param [DataMapper::Query] query
|
224
|
-
# The query used to locate the resources to be
|
224
|
+
# The query used to locate the resources to be matched.
|
225
225
|
#
|
226
226
|
# @param [DataMapper::Operation] the operation for the query
|
227
227
|
#
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DataMapper::Adapters::RedisAdapter do
|
4
|
+
before(:all) do
|
5
|
+
@adapter = DataMapper.setup(:default, {
|
6
|
+
:adapter => "redis",
|
7
|
+
:db => 15
|
8
|
+
})
|
9
|
+
@repository = DataMapper.repository(@adapter.name)
|
10
|
+
@redis = Redis.new(:db => 15)
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
@redis.flushdb
|
15
|
+
end
|
16
|
+
|
17
|
+
# A copy of the encode function from adapater as it is private
|
18
|
+
def encode(value)
|
19
|
+
Base64.encode64(value.to_s).gsub("\n", "")
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "composite keys" do
|
23
|
+
before(:all) do
|
24
|
+
class CompositeFun
|
25
|
+
include DataMapper::Resource
|
26
|
+
|
27
|
+
property :other_id, Integer, :key => true, :required => true, :index => true
|
28
|
+
property :id, Serial, :key => true
|
29
|
+
property :stuff, String
|
30
|
+
|
31
|
+
DataMapper.finalize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be able to create and update an item with a composite key" do
|
36
|
+
c = CompositeFun.new(:other_id => 1)
|
37
|
+
c.save
|
38
|
+
c.update(:stuff => "Random String") # Without the fix in adapter#key_query this throws an exception
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should save the composite id of the resource in the :all and indexed sets" do
|
42
|
+
c = CompositeFun.new(:other_id => 1)
|
43
|
+
c.save
|
44
|
+
|
45
|
+
@redis.hgetall("composite_funs:#{c.other_id}#{c.id}").should == {"other_id" => "#{c.id}"}
|
46
|
+
@redis.smembers("composite_funs:other_id:id:all").should == ["#{c.other_id}#{c.id}"]
|
47
|
+
|
48
|
+
# checks that the member set for the other_id index contains the composite key
|
49
|
+
encoded_other_id = encode(c.other_id)
|
50
|
+
@redis.smembers("composite_funs:other_id:#{encoded_other_id}").should == ["#{c.other_id}#{c.id}"]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-redis-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dm-core
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- lib/dm-redis-adapter.rb
|
217
217
|
- lib/dm-redis-adapter/adapter.rb
|
218
218
|
- lib/dm-redis-adapter/spec/setup.rb
|
219
|
+
- spec/composite_keys_spec.rb
|
219
220
|
- spec/dm_redis_associations_spec.rb
|
220
221
|
- spec/dm_redis_finding_spec.rb
|
221
222
|
- spec/dm_redis_inheritenance_spec.rb
|