swagger 1.3.1 → 1.3.2
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.
- data/VERSION +1 -1
- data/lib/redis_impersonator.rb +11 -1
- data/spec/redis_impersonator_spec.rb +20 -1
- data/swagger.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.2
|
data/lib/redis_impersonator.rb
CHANGED
@@ -87,10 +87,14 @@ class RedisImpersonator
|
|
87
87
|
options = { :conditions => {
|
88
88
|
:key => list_name.to_s,
|
89
89
|
:key_type=> LIST}}
|
90
|
-
|
90
|
+
unless end_range < 0
|
91
|
+
limit = end_range - start_range + 1
|
92
|
+
options.merge!(:limit => limit, :offset => start_range)
|
93
|
+
end
|
91
94
|
values = ResqueValue.all(options)
|
92
95
|
values.map(&:value)
|
93
96
|
end
|
97
|
+
|
94
98
|
|
95
99
|
def lrem(list_name, count, value)
|
96
100
|
raise "Only supports count of 0 which means to remove all elements in list" if count != 0
|
@@ -111,6 +115,12 @@ class RedisImpersonator
|
|
111
115
|
ResqueValue.create!(:key => list_name.to_s, :key_type => LIST, :value => value.to_s)
|
112
116
|
end
|
113
117
|
|
118
|
+
def ltrim(list_name, start_range, end_range)
|
119
|
+
limit = end_range - start_range + 1
|
120
|
+
ids = ResqueValue.all(:select => "id", :conditions => {:key => list_name}, :offset => start_range, :limit => limit)
|
121
|
+
ResqueValue.delete_all(["`key` = ? AND id NOT IN (?)", list_name, ids.collect{|i| i.id}])
|
122
|
+
end
|
123
|
+
|
114
124
|
def keys(pattern = '*')
|
115
125
|
raise "Pattern '#{pattern}' not supported" if pattern != '*'
|
116
126
|
ResqueValue.all(:select => 'DISTINCT resque_values.key').map(&:key)
|
@@ -134,6 +134,25 @@ describe 'RedisImpersonator' do
|
|
134
134
|
impersonator.lrange('some_queue', 0, -1).should include('one')
|
135
135
|
end
|
136
136
|
|
137
|
+
it "should trim according to the specifed start and end" do
|
138
|
+
1.upto(6){|i| impersonator.rpush('some_queue', i)}
|
139
|
+
impersonator.ltrim('some_queue', 1, 3)
|
140
|
+
impersonator.llen('some_queue').should == 3
|
141
|
+
impersonator.lrange('some_queue', 0, 2).should == ["2","3","4"]
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should not affect other keys when trimming" do
|
145
|
+
1.upto(3){|i| impersonator.rpush('some_queue', i)}
|
146
|
+
impersonator.set('something_else', 'independent value')
|
147
|
+
impersonator.ltrim('some_queue', 0, 0)
|
148
|
+
impersonator.get('something_else').should == 'independent value'
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should get a range of values" do
|
152
|
+
1.upto(6){|i| impersonator.rpush('some_queue', i)}
|
153
|
+
impersonator.lrange('some_queue', 0, 5).should == ['1','2','3','4','5','6']
|
154
|
+
impersonator.lrange('some_queue', 1, 3).should == ['2','3','4']
|
155
|
+
end
|
137
156
|
end
|
138
157
|
|
139
158
|
it 'should increment a value' do
|
@@ -149,4 +168,4 @@ describe 'RedisImpersonator' do
|
|
149
168
|
impersonator.decrby('something', 1)
|
150
169
|
impersonator.get('something').should == '1'
|
151
170
|
end
|
152
|
-
end
|
171
|
+
end
|
data/swagger.gemspec
CHANGED