simple_redis_lock 0.1.1 → 0.1.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27defc46c963a46fee2e0fe00644760e482628ed
4
- data.tar.gz: 6ab18186ccd4c6acc7ec3de0146965c5831b68b0
3
+ metadata.gz: fbee306b7d948d7c2b1d918c7db52a2887a9cdec
4
+ data.tar.gz: 6e3a971cf094ca6b1f039a2d4e7ef7d9a10f5ec2
5
5
  SHA512:
6
- metadata.gz: 7a42cc9712b96a3543552316d3302ce30d895d56da33da50d598c16679bee64642c852c927d18bdc1cb5d4cc6de9140b2b8bada62629b0c1c4c5212e24ae7e3b
7
- data.tar.gz: bad7be72052aaea479c4d8f6f3b95310331602655fd4fe352cdc02cd8a1d51b0c0e2e8c19dfbae94602e1487d0e4b21659fd046431e421185cbc9601094099e4
6
+ metadata.gz: 3d96ef9c880b3d40a8d5949451e912daa7265813d30fc35596c0833223e6abf3ce7cadc527d2766e37eed2f162f75ad4c5398ea12f7d8136f50f1b90b4143555
7
+ data.tar.gz: f873136b55b3e20e5dba7b16b5c2a7c2aee10c3f79ed35221eb1a4123e1f4f717e07e39d6f40c9b347a3aef492bae3af794e962ddec30c11b4a68f0d2e1149fe
data/README.md CHANGED
@@ -63,4 +63,14 @@ Or install it yourself as:
63
63
 
64
64
  $ gem install simple_redis_lock
65
65
 
66
+ ## Alternatives:
67
+
68
+ I explored some other awesome alternatives before creating this gem:
69
+
70
+ 1. [mlanett/redis-lock](https://github.com/mlanett/redis-lock)
71
+ 2. [PatrickTulskie/redis-lock](https://github.com/PatrickTulskie/redis-lock)
72
+ 3. [leandromoreira/redlock-rb](https://github.com/leandromoreira/redlock-rb)
73
+ 4. [dv/redis-semaphore](https://github.com/dv/redis-semaphore)
74
+
75
+ but they had too many features of blocking to acquire lock and didn't use this single ```SET KEY 1 NX EX 3600``` awesome atomic redis statement.
66
76
 
@@ -44,7 +44,7 @@ module SimpleRedisLock
44
44
  #
45
45
  def lock(key, expiration)
46
46
  timeout = (expiration * 1000).to_i
47
- if @redis.set(key, Time.now.strftime('%Y-%m-%d %H:%M:%S.%L %z'), nx: true, px: timeout)
47
+ if @redis.set("SimpleRedisLock:#{key}", Time.now.strftime('%Y-%m-%d %H:%M:%S.%L %z'), nx: true, px: timeout)
48
48
  if block_given?
49
49
  begin
50
50
  yield
@@ -58,12 +58,12 @@ module SimpleRedisLock
58
58
  end
59
59
 
60
60
  def release(key)
61
- @redis.del key
61
+ @redis.del "SimpleRedisLock:#{key}"
62
62
  end
63
63
 
64
64
  # time
65
65
  def acquired_at(key)
66
- time_string = @redis.get(key)
66
+ time_string = @redis.get("SimpleRedisLock:#{key}")
67
67
  return nil unless time_string
68
68
 
69
69
  Time.strptime(time_string, '%Y-%m-%d %H:%M:%S.%L %z')
@@ -71,7 +71,7 @@ module SimpleRedisLock
71
71
 
72
72
  # remaining time till lock expiration
73
73
  def ttl(key)
74
- pttl = @redis.pttl(key)
74
+ pttl = @redis.pttl("SimpleRedisLock:#{key}")
75
75
  return nil if pttl == -2
76
76
 
77
77
  pttl.to_f / 1000
@@ -1,3 +1,3 @@
1
1
  module SimpleRedisLock
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_redis_lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nitzan Aviram
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler