Module: Redis::ZSets

Defined in:
lib/redis/zsets.rb

Instance Method Summary collapse

Instance Method Details

#redis_ZADD(key, score, member) ⇒ Object



177
178
179
180
181
182
# File 'lib/redis/zsets.rb', line 177

def redis_ZADD key, score, member
  record = (@database[key] ||= ZSet.new)
  result = !record.include?(member)
  record.add member, redis_f(score)
  result
end

#redis_ZCARD(key) ⇒ Object



219
220
221
# File 'lib/redis/zsets.rb', line 219

def redis_ZCARD key
  (@database[key] || []).size
end

#redis_ZCOUNT(key, min, max) ⇒ Object



232
233
234
235
# File 'lib/redis/zsets.rb', line 232

def redis_ZCOUNT key, min, max
  record = @database[key] || ZSet.new
  record.range_by_score(false, min, max, self).size
end

#redis_ZINCRBY(key, increment, member) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/redis/zsets.rb', line 184

def redis_ZINCRBY key, increment, member
  record = (@database[key] ||= ZSet.new)
  increment = redis_f increment
  if record.include?(member)
    score = record.score(member) + increment
  else
    score = increment
  end
  raise 'NaN' if score.nan?
  record.add member, score
  score
end

#redis_ZINTERSTORE(destination, numkeys, *args) ⇒ Object



274
275
276
# File 'lib/redis/zsets.rb', line 274

def redis_ZINTERSTORE destination, numkeys, *args
  ZSet.aggregate @database, true, destination, numkeys, self, *args      
end

#redis_ZRANGE(key, start, stop, withscores = false) ⇒ Object



247
248
249
250
251
252
# File 'lib/redis/zsets.rb', line 247

def redis_ZRANGE key, start ,stop, withscores = false
  record = @database[key] || ZSet.new
  start = redis_i start
  stop = redis_i stop
  record.range false, start, stop, self, withscores
end

#redis_ZRANGEBYSCORE(key, min, max, *args) ⇒ Object



242
243
244
245
# File 'lib/redis/zsets.rb', line 242

def redis_ZRANGEBYSCORE key, min, max, *args
  record = @database[key] || ZSet.new
  record.range_by_score false, min, max, self, *args
end

#redis_ZRANK(key, member) ⇒ Object



197
198
199
200
# File 'lib/redis/zsets.rb', line 197

def redis_ZRANK key, member
  record = (@database[key] || ZSet.new).to_a
  record.index {|i| i[0]==member}
end

#redis_ZREM(key, member) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/redis/zsets.rb', line 202

def redis_ZREM key, member
  record = @database[key] || []
  return false unless record.include? member
  record.delete member
  @database.delete key if record.empty?
  return true
end

#redis_ZREMRANGEBYRANK(key, start, stop) ⇒ Object



261
262
263
264
265
266
267
268
# File 'lib/redis/zsets.rb', line 261

def redis_ZREMRANGEBYRANK key, start, stop
  record = @database[key] || ZSet.new
  range = record.range false, start, stop, self
  range.each do |member, score|
    record.delete member
  end
  range.size
end

#redis_ZREMRANGEBYSCORE(key, min, max) ⇒ Object



223
224
225
226
227
228
229
230
# File 'lib/redis/zsets.rb', line 223

def redis_ZREMRANGEBYSCORE key, min, max
  record = @database[key] || ZSet.new
  range = record.range_by_score(false, min, max, self)
  range.each do |member, score|
    record.delete member
  end
  range.size
end

#redis_ZREVRANGE(key, start, stop, withscores = false) ⇒ Object



254
255
256
257
258
259
# File 'lib/redis/zsets.rb', line 254

def redis_ZREVRANGE key, start ,stop, withscores = false
  record = @database[key] || ZSet.new
  start = redis_i start
  stop = redis_i stop
  record.range true, start, stop, self, withscores
end

#redis_ZREVRANGEBYSCORE(key, min, max, *args) ⇒ Object



237
238
239
240
# File 'lib/redis/zsets.rb', line 237

def redis_ZREVRANGEBYSCORE key, min, max, *args
  record = @database[key] || ZSet.new
  record.range_by_score true, min, max, self, *args
end

#redis_ZREVRANK(key, member) ⇒ Object



214
215
216
217
# File 'lib/redis/zsets.rb', line 214

def redis_ZREVRANK key, member
  record = (@database[key] || ZSet.new).to_a_reverse
  record.index {|i| i[0]==member}
end

#redis_ZSCORE(key, member) ⇒ Object



210
211
212
# File 'lib/redis/zsets.rb', line 210

def redis_ZSCORE key, member
  (@database[key] || ZSet.new).score member
end

#redis_ZUNIONSTORE(destination, numkeys, *args) ⇒ Object



270
271
272
# File 'lib/redis/zsets.rb', line 270

def redis_ZUNIONSTORE destination, numkeys, *args
  ZSet.aggregate @database, false, destination, numkeys, self, *args      
end