ohm 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +4 -4
  2. data/.gems +3 -3
  3. data/CHANGELOG.md +9 -0
  4. data/README.md +4 -0
  5. data/lib/ohm.rb +29 -20
  6. data/ohm.gemspec +2 -2
  7. data/test/model.rb +10 -0
  8. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3aab8e61021f4edc8be614c9804068a0412f521d
4
- data.tar.gz: 7edd271f3f609d5a9b8701b67145d55c68ffa271
3
+ metadata.gz: ed9503debac38501951e7e6847229e79e1289626
4
+ data.tar.gz: a754d5fef582a8c80dc1ad3b51b006820d03006a
5
5
  SHA512:
6
- metadata.gz: 87db7ed730a34029c2aeb84f16a79ea480918abfeff970a84d1ba0393b06b572a00a6017ca18acc79fc1768c981a40c2016c663b40c5e45c75261227d86647d4
7
- data.tar.gz: c5ef751dcb8b25b7348d9e0dba04029d207c567274912b28c87e92b86e5b4b344896aa3a1df072c1510d045340d20c0aee6b9adf7b1b278d2bc00d1dd9ff70f5
6
+ metadata.gz: cad32b03019a2c5f2e058446cb44947e0f3261e8d9c6dd30ff780eb21c7382e4384da950e057d0762307682f25fde152dda8b8f1f59f991642315c8cbf254ef0
7
+ data.tar.gz: 3e2ecb21022c7fb91441077a6d2566e344c61cba242a93b9675a9a41c0271448321c0ab2e2b9daa2b3110d97856d7d6d30a1675be2ae77362d927b8a313e852f
data/.gems CHANGED
@@ -1,5 +1,5 @@
1
- msgpack -v 0.6.0
2
- nido -v 0.0.1
3
1
  redic -v 1.5.0
4
- cutest -v 1.2.2
2
+ msgpack -v 0.6.2
3
+ nido -v 0.0.1
5
4
  stal -v 0.1.0
5
+ cutest -v 1.2.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 2.3.0
2
+
3
+ - Retry save and delete if scripts were flushed in the server.
4
+ - Depend on Redic ~> 1.5.0 in order to use of `call!` instead of `call`.
5
+
6
+ ## 2.2.1
7
+
8
+ - Lock msgpack version
9
+
1
10
  ## 2.2.0
2
11
 
3
12
  - Use Stal for set operations
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
- response = script(LUA_SAVE, 0,
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
- cache = LUA_CACHE[redis.url]
1344
+ begin
1345
+ cache = LUA_CACHE[redis.url]
1350
1346
 
1351
- if cache.key?(file)
1352
- sha = cache[file]
1353
- else
1354
- src = File.read(file)
1355
- sha = redis.call("SCRIPT", "LOAD", src)
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
- cache[file] = sha
1358
- end
1353
+ cache[file] = sha
1354
+ end
1355
+
1356
+ redis.call!("EVALSHA", sha, *args)
1357
+
1358
+ rescue RuntimeError
1359
1359
 
1360
- redis.call("EVALSHA", sha, *args)
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.2.1"
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.2.1
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-05-28 00:00:00.000000000 Z
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: '0'
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: '0'
28
+ version: 1.5.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: nido
31
31
  requirement: !ruby/object:Gem::Requirement