ohm 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gems +3 -3
- data/CHANGELOG.md +9 -0
- data/README.md +4 -0
- data/lib/ohm.rb +29 -20
- data/ohm.gemspec +2 -2
- data/test/model.rb +10 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed9503debac38501951e7e6847229e79e1289626
|
4
|
+
data.tar.gz: a754d5fef582a8c80dc1ad3b51b006820d03006a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cad32b03019a2c5f2e058446cb44947e0f3261e8d9c6dd30ff780eb21c7382e4384da950e057d0762307682f25fde152dda8b8f1f59f991642315c8cbf254ef0
|
7
|
+
data.tar.gz: 3e2ecb21022c7fb91441077a6d2566e344c61cba242a93b9675a9a41c0271448321c0ab2e2b9daa2b3110d97856d7d6d30a1675be2ae77362d927b8a313e852f
|
data/.gems
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -152,6 +152,10 @@ event.id
|
|
152
152
|
event == Event[1]
|
153
153
|
# => true
|
154
154
|
|
155
|
+
# Update an event
|
156
|
+
event.update :name => "Ohm Worldwide Conference 2032"
|
157
|
+
# => #<Event:0x007fb4c35e2458 @attributes={:name=>"Ohm Worldwide Conference"}, @_memo={}, @id="1">
|
158
|
+
|
155
159
|
# Trying to find a non existent event
|
156
160
|
Event[2]
|
157
161
|
# => nil
|
data/lib/ohm.rb
CHANGED
@@ -39,6 +39,11 @@ module Ohm
|
|
39
39
|
class IndexNotFound < Error; end
|
40
40
|
class UniqueIndexViolation < Error; end
|
41
41
|
|
42
|
+
module ErrorPatterns
|
43
|
+
DUPLICATE = /(UniqueIndexViolation: (\w+))/.freeze
|
44
|
+
NOSCRIPT = /^NOSCRIPT/.freeze
|
45
|
+
end
|
46
|
+
|
42
47
|
# Instead of monkey patching Kernel or trying to be clever, it's
|
43
48
|
# best to confine all the helper methods in a Utils module.
|
44
49
|
module Utils
|
@@ -1299,23 +1304,13 @@ module Ohm
|
|
1299
1304
|
features["id"] = @id
|
1300
1305
|
end
|
1301
1306
|
|
1302
|
-
|
1307
|
+
@id = script(LUA_SAVE, 0,
|
1303
1308
|
features.to_msgpack,
|
1304
1309
|
_sanitized_attributes.to_msgpack,
|
1305
1310
|
indices.to_msgpack,
|
1306
1311
|
uniques.to_msgpack
|
1307
1312
|
)
|
1308
1313
|
|
1309
|
-
if response.is_a?(RuntimeError)
|
1310
|
-
if response.message =~ /(UniqueIndexViolation: (\w+))/
|
1311
|
-
raise UniqueIndexViolation, $1
|
1312
|
-
else
|
1313
|
-
raise response
|
1314
|
-
end
|
1315
|
-
end
|
1316
|
-
|
1317
|
-
@id = response
|
1318
|
-
|
1319
1314
|
return self
|
1320
1315
|
end
|
1321
1316
|
|
@@ -1346,18 +1341,32 @@ module Ohm
|
|
1346
1341
|
# Run lua scripts and cache the sha in order to improve
|
1347
1342
|
# successive calls.
|
1348
1343
|
def script(file, *args)
|
1349
|
-
|
1344
|
+
begin
|
1345
|
+
cache = LUA_CACHE[redis.url]
|
1350
1346
|
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1347
|
+
if cache.key?(file)
|
1348
|
+
sha = cache[file]
|
1349
|
+
else
|
1350
|
+
src = File.read(file)
|
1351
|
+
sha = redis.call("SCRIPT", "LOAD", src)
|
1356
1352
|
|
1357
|
-
|
1358
|
-
|
1353
|
+
cache[file] = sha
|
1354
|
+
end
|
1355
|
+
|
1356
|
+
redis.call!("EVALSHA", sha, *args)
|
1357
|
+
|
1358
|
+
rescue RuntimeError
|
1359
1359
|
|
1360
|
-
|
1360
|
+
case $!.message
|
1361
|
+
when ErrorPatterns::NOSCRIPT
|
1362
|
+
LUA_CACHE[redis.url].clear
|
1363
|
+
retry
|
1364
|
+
when ErrorPatterns::DUPLICATE
|
1365
|
+
raise UniqueIndexViolation, $1
|
1366
|
+
else
|
1367
|
+
raise $!
|
1368
|
+
end
|
1369
|
+
end
|
1361
1370
|
end
|
1362
1371
|
|
1363
1372
|
# Update the model attributes and call save.
|
data/ohm.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "ohm"
|
3
|
-
s.version = "2.
|
3
|
+
s.version = "2.3.0"
|
4
4
|
s.summary = %{Object-hash mapping library for Redis.}
|
5
5
|
s.description = %Q{Ohm is a library that allows to store an object in Redis, a persistent key-value database. It has very good performance.}
|
6
6
|
s.authors = ["Michel Martens", "Damian Janowski", "Cyril David"]
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.rubyforge_project = "ohm"
|
14
14
|
|
15
|
-
s.add_dependency "redic"
|
15
|
+
s.add_dependency "redic", "~> 1.5.0"
|
16
16
|
s.add_dependency "nido"
|
17
17
|
s.add_dependency "stal"
|
18
18
|
s.add_dependency "msgpack", "~> 0.5.0"
|
data/test/model.rb
CHANGED
@@ -787,3 +787,13 @@ test "poster-example for overriding writers" do
|
|
787
787
|
a = Advertiser.new(:email => " FOO@BAR.COM ")
|
788
788
|
assert_equal "foo@bar.com", a.email
|
789
789
|
end
|
790
|
+
|
791
|
+
test "scripts are flushed" do
|
792
|
+
m = Meetup.create(:name => "Foo")
|
793
|
+
|
794
|
+
Meetup.redis.call("SCRIPT", "FLUSH")
|
795
|
+
|
796
|
+
m.update(:name => "Bar")
|
797
|
+
|
798
|
+
assert_equal m.name, Meetup[m.id].name
|
799
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-08-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: redic
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
28
|
+
version: 1.5.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: nido
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|