Class: RedisThrottle::Concurrency

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_throttle/concurrency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, limit:, ttl:) ⇒ Concurrency

Returns a new instance of Concurrency.

Parameters:

  • bucket (#to_s)

    Throttling group name

  • limit (#to_i)

    Max allowed concurrent units

  • ttl (#to_i)

    Time (in seconds) to hold the lock before releasing it (in case it wasn’t released already)



22
23
24
25
26
# File 'lib/redis_throttle/concurrency.rb', line 22

def initialize(bucket, limit:, ttl:)
  @bucket = -bucket.to_s
  @limit  = limit.to_i
  @ttl    = ttl.to_i
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



7
8
9
# File 'lib/redis_throttle/concurrency.rb', line 7

def bucket
  @bucket
end

#limitObject (readonly)

Returns the value of attribute limit.



11
12
13
# File 'lib/redis_throttle/concurrency.rb', line 11

def limit
  @limit
end

#ttlObject (readonly)

Returns the value of attribute ttl.



16
17
18
# File 'lib/redis_throttle/concurrency.rb', line 16

def ttl
  @ttl
end

Instance Method Details

#<=>(other) ⇒ -1, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compare ‘self` with `other` strategy:

Returns:

  • (-1, 0, 1, nil)


54
55
56
# File 'lib/redis_throttle/concurrency.rb', line 54

def <=>(other)
  complexity <=> other.complexity if other.respond_to? :complexity
end

#==(other) ⇒ Boolean Also known as: eql?

Returns ‘true` if `other` is a RedisThrottle::Concurrency instance with the same #bucket, #limit, and #ttl.

Parameters:

  • other (Object)

Returns:

  • (Boolean)

See Also:



34
35
36
37
38
39
# File 'lib/redis_throttle/concurrency.rb', line 34

def ==(other)
  return true  if equal? other
  return false unless other.is_a?(self.class)

  @bucket == other.bucket && @limit == other.limit && @ttl == other.ttl
end

#complexityArray(Integer, Integer)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Strategy complexity pseudo-score.

Returns:

  • (Array(Integer, Integer))

    Strategy complexity pseudo-score



71
72
73
# File 'lib/redis_throttle/concurrency.rb', line 71

def complexity
  [1, @limit]
end

#hashInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generates an Integer hash value for this object.



64
65
66
# File 'lib/redis_throttle/concurrency.rb', line 64

def hash
  @hash ||= [@bucket, @limit, @ttl].hash
end