redpear 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redpear/store/base.rb +14 -8
- data/lib/redpear/store/hash.rb +4 -8
- data/lib/redpear/store/list.rb +1 -6
- data/lib/redpear/store/lock.rb +1 -1
- data/lib/redpear/store/set.rb +2 -2
- data/lib/redpear/store/value.rb +3 -3
- data/lib/redpear/version.rb +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43b9457346f8717f197abb7126edf776529ac0a7
|
4
|
+
data.tar.gz: ba0cfb07aadfb5c6d9aed9a2a6db569e75d6472c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb419ed421012e2ddcf0a1d4075df2dc6b7e574a7a7bdb9dbb3d212876add05e4323ab4a3fce6e70cfff8840a9e6945afaacdcf658c6acd2155daacdd7a37d89
|
7
|
+
data.tar.gz: c9a515798435daf015f72795356b388e9b4344bcbd307014974a2b726b6fada421410e426edc257029ebf52e73613a87e8c1adaefb1083c3a67fa68213e64690
|
data/lib/redpear/store/base.rb
CHANGED
@@ -3,12 +3,13 @@ require 'securerandom'
|
|
3
3
|
class Redpear::Store::Base
|
4
4
|
|
5
5
|
# Transforamtions
|
6
|
-
IS_NIL =
|
7
|
-
IS_ZERO =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
IS_NIL = ->v { v.nil? }.freeze
|
7
|
+
IS_ZERO = ->v { v.zero? }.freeze
|
8
|
+
IS_ONE = ->v { v == 1 }.freeze
|
9
|
+
IS_TRUE = ->v { !!v }.freeze
|
10
|
+
TO_INT = ->v { v.to_i }.freeze
|
11
|
+
TO_SET = ->v { v.to_set }.freeze
|
12
|
+
PICK_FIRST = ->v { v.first }.freeze
|
12
13
|
|
13
14
|
attr_reader :key, :conn
|
14
15
|
|
@@ -54,7 +55,7 @@ class Redpear::Store::Base
|
|
54
55
|
|
55
56
|
# @return [Boolean] true if the record exists
|
56
57
|
def exists?
|
57
|
-
|
58
|
+
conn.exists(key)
|
58
59
|
end
|
59
60
|
|
60
61
|
# Watch this key
|
@@ -96,7 +97,12 @@ class Redpear::Store::Base
|
|
96
97
|
|
97
98
|
# Deletes the whole record
|
98
99
|
def purge!
|
99
|
-
conn.del(key)
|
100
|
+
case value = conn.del(key)
|
101
|
+
when Redis::Future
|
102
|
+
value.instance_eval { @transformation = IS_ONE }
|
103
|
+
else
|
104
|
+
value == 1
|
105
|
+
end
|
100
106
|
end
|
101
107
|
|
102
108
|
# Deletes the record and returns the value
|
data/lib/redpear/store/hash.rb
CHANGED
@@ -22,7 +22,7 @@ class Redpear::Store::Hash < Redpear::Store::Enumerable
|
|
22
22
|
|
23
23
|
# @return [Boolean] true, if field exists
|
24
24
|
def key?(field)
|
25
|
-
|
25
|
+
conn.hexists(key, field)
|
26
26
|
end
|
27
27
|
alias_method :has_key?, :key?
|
28
28
|
alias_method :member?, :key?
|
@@ -101,13 +101,9 @@ class Redpear::Store::Hash < Redpear::Store::Enumerable
|
|
101
101
|
|
102
102
|
# @param [Hash] hash
|
103
103
|
# The pairs to update
|
104
|
-
def update(hash)
|
105
|
-
|
106
|
-
|
107
|
-
result
|
108
|
-
else
|
109
|
-
to_hash
|
110
|
-
end
|
104
|
+
def update(hash)
|
105
|
+
result = merge!(hash)
|
106
|
+
Redis::Future === result ? result : to_hash
|
111
107
|
end
|
112
108
|
|
113
109
|
# @param [Hash] hash
|
data/lib/redpear/store/list.rb
CHANGED
@@ -51,12 +51,7 @@ class Redpear::Store::List < Redpear::Store::Enumerable
|
|
51
51
|
else
|
52
52
|
trim(start, start + length - 1)
|
53
53
|
end
|
54
|
-
|
55
|
-
when Redis::Future
|
56
|
-
result
|
57
|
-
else
|
58
|
-
to_a
|
59
|
-
end
|
54
|
+
Redis::Future === result ? result : to_a
|
60
55
|
end
|
61
56
|
|
62
57
|
# @param [Integer] start
|
data/lib/redpear/store/lock.rb
CHANGED
data/lib/redpear/store/set.rb
CHANGED
@@ -15,7 +15,7 @@ class Redpear::Store::Set < Redpear::Store::Enumerable
|
|
15
15
|
value.instance_eval { @transformation = TO_SET }
|
16
16
|
else
|
17
17
|
value.to_set
|
18
|
-
end
|
18
|
+
end
|
19
19
|
end
|
20
20
|
alias_method :to_set, :all
|
21
21
|
alias_method :value, :all
|
@@ -50,7 +50,7 @@ class Redpear::Store::Set < Redpear::Store::Enumerable
|
|
50
50
|
|
51
51
|
# @return [Boolean] true, if value is included
|
52
52
|
def include?(value)
|
53
|
-
|
53
|
+
conn.sismember(key, value)
|
54
54
|
end
|
55
55
|
alias_method :member?, :include?
|
56
56
|
|
data/lib/redpear/store/value.rb
CHANGED
@@ -45,8 +45,8 @@ class Redpear::Store::Value < Redpear::Store::Base
|
|
45
45
|
def ==(other)
|
46
46
|
case value = self.value
|
47
47
|
when Redis::Future
|
48
|
-
value.instance_eval { @transformation =
|
49
|
-
else
|
48
|
+
value.instance_eval { @transformation = ->v { v == other } }
|
49
|
+
else
|
50
50
|
value == other
|
51
51
|
end
|
52
52
|
end
|
@@ -56,7 +56,7 @@ class Redpear::Store::Value < Redpear::Store::Base
|
|
56
56
|
case value = self.value
|
57
57
|
when Redis::Future
|
58
58
|
value.instance_eval { @transformation = IS_NIL }
|
59
|
-
else
|
59
|
+
else
|
60
60
|
value.nil?
|
61
61
|
end
|
62
62
|
end
|
data/lib/redpear/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redpear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
@@ -14,16 +14,22 @@ dependencies:
|
|
14
14
|
name: redis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.5
|
20
|
+
- - <
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
22
|
+
version: 3.1.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.5
|
30
|
+
- - <
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
32
|
+
version: 3.1.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|