Class: Chimera::RedisObjectProxy::ZSet

Inherits:
Collection show all
Defined in:
lib/chimera/redis_objects.rb

Instance Attribute Summary

Attributes inherited from Base

#extra_opts, #name, #owner

Instance Method Summary collapse

Methods inherited from Collection

#sort

Methods inherited from Base

#connection, #decode, #destroy, #encode, #initialize, #key

Constructor Details

This class inherits a constructor from Chimera::RedisObjectProxy::Base

Instance Method Details

#add(val, score = 0) ⇒ Object



190
191
192
# File 'lib/chimera/redis_objects.rb', line 190

def add(val,score=0)
  connection.zadd(self.key, score, encode(val))
end

#cardObject Also known as: size, count



237
238
239
# File 'lib/chimera/redis_objects.rb', line 237

def card
  connection.zcard(self.key).to_i
end

#incrby(val, incr) ⇒ Object Also known as: incr_by



198
199
200
# File 'lib/chimera/redis_objects.rb', line 198

def incrby(val, incr)
  connection.zincrby(self.key, incr.to_f, encode(val))
end

#range(start_index, end_index, extra_opts = {}) ⇒ Object



204
205
206
207
208
# File 'lib/chimera/redis_objects.rb', line 204

def range(start_index, end_index, extra_opts={})
  opts = [self.key, start_index.to_i, end_index.to_i]
  opts << "WITHSCORES" if extra_opts[:with_scores] == true
  (connection.zrange(opts) || []).collect { |val| decode(val) }
end

#rangebyscore(min, max, extra_opts = {}) ⇒ Object Also known as: range_by_score



218
219
220
221
222
223
224
225
226
# File 'lib/chimera/redis_objects.rb', line 218

def rangebyscore(min, max, extra_opts={})
  opts = [self.key, min.to_f, max.to_f]
  offset, count = extra_opts[:limit]
  if offset and count
    opts << "LIMIT #{offset} #{count}"
  end
  opts << "WITHSCORES" if extra_opts[:with_scores] == true
  (connection.zrangebyscore(opts) || []).collect { |val| decode(val) }
end

#rem(val) ⇒ Object



194
195
196
# File 'lib/chimera/redis_objects.rb', line 194

def rem(val)
  connection.zrem(self.key, encode(val))
end

#remrangebyscore(min, max) ⇒ Object Also known as: rem_range_by_score, remove_range_by_score



230
231
232
# File 'lib/chimera/redis_objects.rb', line 230

def remrangebyscore(min,max)
  connection.zremrangebyscore(self.key,min.to_f,max.to_f)
end

#revrange(start_index, end_index, extra_opts = {}) ⇒ Object Also known as: rev_range



210
211
212
213
214
# File 'lib/chimera/redis_objects.rb', line 210

def revrange(start_index, end_index, extra_opts={})
  opts = [self.key, start_index.to_i, end_index.to_i]
  opts << "WITHSCORES" if extra_opts[:with_scores] == true
  (connection.zrevrange(opts) || []).collect { |val| decode(val) }
end

#score(val) ⇒ Object



244
245
246
# File 'lib/chimera/redis_objects.rb', line 244

def score(val)
  connection.zscore(self.key, val).to_f
end