redtastic 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/redtastic/model.rb +12 -2
- data/lib/redtastic/version.rb +1 -1
- data/spec/model_spec.rb +29 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjQ3MDMwNWYyYjA3MDEzMjFlOWEwMmIwODljNTUyYTliOTlkNGQzMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmU4MjljYjQxZjRiZDhkMWVhZmViZGM3MDA0YjM1NmE4MTA3NmU3Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGE4ZTVhMzY3MTczN2ZjMjMzY2U5NWZmYzNjZDgzMzA0YjZmMjJhOWJlODQ5
|
10
|
+
YmQyMmUxZTQ1ZWQ5OWY2ZmNhZTk4MTliMDhkYjMwNGRmZmJiN2FiOTgwMzFi
|
11
|
+
ZGY0ZGRlMjZkMThmYzNjZDNjMThiMmFhMWZlZGYzMDFiMDgwZjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGE3N2QzNzUxNWUwZTlhNWM2MDlhMzE4MmQ2MDNmYTdjZDA4NjliOTgxN2Yz
|
14
|
+
N2ZmNzI2YmI5YTg2NGM3ZjUxYWU4N2QzOTExODAwNTM4NTVlYzQ5NTZhOTdi
|
15
|
+
MDliMTViYjM5NjA5OTNmODdmZTEzNzY5ZWZjZmM2YzllYThlZWY=
|
data/Gemfile.lock
CHANGED
data/lib/redtastic/model.rb
CHANGED
@@ -10,7 +10,12 @@ module Redtastic
|
|
10
10
|
argv << params[:unique_id]
|
11
11
|
Redtastic::ScriptManager.msadd(key_data[0], argv)
|
12
12
|
else
|
13
|
-
|
13
|
+
if params[:by].present?
|
14
|
+
increment_by = params[:by]
|
15
|
+
else
|
16
|
+
increment_by = 1
|
17
|
+
end
|
18
|
+
Redtastic::ScriptManager.hmincrby(key_data[0], key_data[1].unshift(increment_by))
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
@@ -21,7 +26,12 @@ module Redtastic
|
|
21
26
|
argv << params[:unique_id]
|
22
27
|
Redtastic::ScriptManager.msrem(key_data[0], argv)
|
23
28
|
else
|
24
|
-
|
29
|
+
if params[:by].present?
|
30
|
+
decrement_by = params[:by]
|
31
|
+
else
|
32
|
+
decrement_by = 1
|
33
|
+
end
|
34
|
+
Redtastic::ScriptManager.hmincrby(key_data[0], key_data[1].unshift(-1*decrement_by))
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
data/lib/redtastic/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -63,6 +63,18 @@ describe Redtastic::Model do
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
+
context 'when specifying the \'by\' parameter' do
|
67
|
+
it 'increments the key by the given amount' do
|
68
|
+
Visits.increment(timestamp: @timestamp, id: @id, by: 5)
|
69
|
+
expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('5')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'allows for negative increments' do
|
73
|
+
Visits.increment(timestamp: @timestamp, id: @id, by: -5)
|
74
|
+
expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('-5')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
66
78
|
context 'a model with no resolution' do
|
67
79
|
it 'increments the key' do
|
68
80
|
NoResolutions.increment(id: @id)
|
@@ -85,17 +97,29 @@ describe Redtastic::Model do
|
|
85
97
|
end
|
86
98
|
|
87
99
|
describe '#decrement' do
|
88
|
-
before do
|
89
|
-
Redtastic::Connection.redis.hset(@day_key, @index, '1')
|
90
|
-
Visits.decrement(timestamp: @timestamp, id: @id)
|
91
|
-
end
|
92
|
-
|
93
100
|
context 'a model with a resolution' do
|
101
|
+
before do
|
102
|
+
Redtastic::Connection.redis.hset(@day_key, @index, '1')
|
103
|
+
Visits.decrement(timestamp: @timestamp, id: @id)
|
104
|
+
end
|
105
|
+
|
94
106
|
it 'decrements the key' do
|
95
107
|
expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('0')
|
96
108
|
end
|
97
109
|
end
|
98
110
|
|
111
|
+
context 'when specifying the \'by\' parameter' do
|
112
|
+
it 'decrements the key by the given amount' do
|
113
|
+
Visits.decrement(timestamp: @timestamp, id: @id, by: 5)
|
114
|
+
expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('-5')
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'allows for negative decrements' do
|
118
|
+
Visits.decrement(timestamp: @timestamp, id: @id, by: -5)
|
119
|
+
expect(Redtastic::Connection.redis.hget(@day_key, @index)).to eq('5')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
99
123
|
context 'a model with no resolution' do
|
100
124
|
before do
|
101
125
|
Redtastic::Connection.redis.hset(@no_resolution_key, @index, '1')
|