activeredis 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/activeredis/version.rb +1 -1
- data/lib/activeredis.rb +28 -4
- metadata +2 -3
data/lib/activeredis/version.rb
CHANGED
data/lib/activeredis.rb
CHANGED
@@ -31,7 +31,7 @@ class Module
|
|
31
31
|
end
|
32
32
|
|
33
33
|
module ActiveRedis
|
34
|
-
module_attr_accessor :host, :port
|
34
|
+
module_attr_accessor :host, :port, :fast_find_field
|
35
35
|
@@host = "localhost"
|
36
36
|
@@port = "6379"
|
37
37
|
|
@@ -98,7 +98,13 @@ module ActiveRedis
|
|
98
98
|
connection.hset("#{key_namespace}:attributes", key, value)
|
99
99
|
}
|
100
100
|
end
|
101
|
-
|
101
|
+
if ActiveRedis.fast_find_field != nil
|
102
|
+
connection.hset("#{class_namespace}:fast_find_field", @attributes[ActiveRedis.fast_find_field.to_s].to_s, @id)
|
103
|
+
if self.class._fields.include?(:no)
|
104
|
+
connection.hset("#{class_namespace}:no", @attributes[:no.to_s].to_s, @id)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
connection.zadd("#{class_namespace}:all", @id, @id)
|
102
108
|
end
|
103
109
|
true
|
104
110
|
end
|
@@ -135,6 +141,12 @@ module ActiveRedis
|
|
135
141
|
|
136
142
|
def destroy
|
137
143
|
connection.multi do
|
144
|
+
if ActiveRedis.fast_find_field != nil
|
145
|
+
connection.hdel "#{class_namespace}:fast_find_field", @attributes[ActiveRedis.fast_find_field.to_s].to_s
|
146
|
+
if self.class._fields.include?(:no)
|
147
|
+
connection.hdel "#{class_namespace}:no", @attributes[:no.to_s].to_s
|
148
|
+
end
|
149
|
+
end
|
138
150
|
connection.del "#{key_namespace}:attributes"
|
139
151
|
connection.zrem "#{class_namespace}:all", @id
|
140
152
|
@frozen = true
|
@@ -171,7 +183,7 @@ module ActiveRedis
|
|
171
183
|
if field.to_sym == :updated_at
|
172
184
|
Time.parse(@attributes["#{field}"])
|
173
185
|
else
|
174
|
-
@attributes["#{field}"]
|
186
|
+
@attributes["#{field}"]
|
175
187
|
end
|
176
188
|
end
|
177
189
|
|
@@ -239,6 +251,9 @@ module ActiveRedis
|
|
239
251
|
records.each do |record|
|
240
252
|
record.destroy
|
241
253
|
end
|
254
|
+
if ActiveRedis.fast_find_field != nil
|
255
|
+
connection.del "#{key_namespace}:fast_find_field", "#{key_namespace}:no"
|
256
|
+
end
|
242
257
|
end
|
243
258
|
|
244
259
|
def self.find(id)
|
@@ -262,7 +277,8 @@ module ActiveRedis
|
|
262
277
|
end
|
263
278
|
|
264
279
|
def self.find_by_param(field, value)
|
265
|
-
|
280
|
+
find_id = self.fast_find_by_param(field, value)
|
281
|
+
return find(find_id) if find_id != nil
|
266
282
|
ids = connection.zrange "#{key_namespace}:all", 0, count
|
267
283
|
ids.each do |id|
|
268
284
|
record = find(id)
|
@@ -273,6 +289,14 @@ module ActiveRedis
|
|
273
289
|
nil
|
274
290
|
end
|
275
291
|
|
292
|
+
def self.fast_find_by_param(field, value)
|
293
|
+
if ActiveRedis.fast_find_field != nil && ActiveRedis.fast_find_field == field
|
294
|
+
find_id = connection.hget "#{key_namespace}:fast_find_field", value
|
295
|
+
elsif field == :no
|
296
|
+
find_id = connection.hget "#{key_namespace}:no", value
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
276
300
|
def self.method_missing(name, *args)
|
277
301
|
return find_by_param($1.to_sym, args[0]) if name.to_s =~ /^find_by_(.*)/
|
278
302
|
return find_all_by_param($1.to_sym, args[0]) if name.to_s =~ /^find_all_by_(.*)/
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redis
|
@@ -110,4 +110,3 @@ summary: ActiveModel based object persisting library for Redis key-value databas
|
|
110
110
|
test_files:
|
111
111
|
- spec/active_redis_spec.rb
|
112
112
|
- spec/spec_helper.rb
|
113
|
-
has_rdoc:
|