redismodel 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redismodel.rb +6 -3
- data/test/benchmarks.rb +8 -3
- metadata +2 -2
data/lib/redismodel.rb
CHANGED
@@ -47,6 +47,10 @@ class RedisModel
|
|
47
47
|
@connections[klass.to_s] ||= Redis.new(hash)
|
48
48
|
end
|
49
49
|
|
50
|
+
def self.version
|
51
|
+
VERSION
|
52
|
+
end
|
53
|
+
|
50
54
|
|
51
55
|
# Casts a object type as a compatible type for redis, or reverses the process.
|
52
56
|
#
|
@@ -96,7 +100,7 @@ class RedisModel
|
|
96
100
|
if hash[:id].nil?
|
97
101
|
|
98
102
|
self.send("id=", generate_uniq_token)
|
99
|
-
|
103
|
+
if self.class.properties.include?(:created_at)
|
100
104
|
set :created_at, DateTime.now
|
101
105
|
end
|
102
106
|
hash.to_a.each do |property|
|
@@ -271,8 +275,7 @@ class RedisModel
|
|
271
275
|
value = RedisModel.cast c, value
|
272
276
|
redis.set "#{self.class}:#{id}:#{property}", value
|
273
277
|
@_data[property] = value
|
274
|
-
|
275
|
-
unless property == :updated_at && !self.class.properties[:updated_at].nil?
|
278
|
+
unless property == :updated_at || !self.class.properties.include?(:updated_at)
|
276
279
|
set :updated_at, DateTime.now
|
277
280
|
end
|
278
281
|
end
|
data/test/benchmarks.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'benchmark'
|
2
|
-
|
2
|
+
require File.dirname(__FILE__) + '/../lib/redismodel' unless defined? RedisModel
|
3
|
+
Dir.glob("test/models/*.rb").each{|f| require f}
|
4
|
+
|
5
|
+
SIZE = 100
|
3
6
|
|
4
7
|
Person.destroy_all
|
5
8
|
|
@@ -13,9 +16,11 @@ puts Benchmark.measure{
|
|
13
16
|
end
|
14
17
|
}
|
15
18
|
|
16
|
-
|
19
|
+
Person.destroy_all
|
20
|
+
|
21
|
+
puts "Create #{SIZE} records"
|
17
22
|
puts Benchmark.measure{
|
18
|
-
|
23
|
+
SIZE.times do
|
19
24
|
Person.new(
|
20
25
|
:name => "ashley",
|
21
26
|
:age => 18
|