Sha256: 63da38b4d50e059d0cd045a7d00f1328870a0295e0e9c6076489d1ee990c3990

Contents?: true

Size: 1.61 KB

Versions: 19

Compression:

Stored size: 1.61 KB

Contents

# encoding: utf-8
module ServiceHelpers
  def svcapi_getkey(service)
    $redis.brpoplpush("apikey:available:#{service}", "apikey:inuse:#{service}", 120)
  end
  def svcapi_releasekey(service, key)
    $redis.lrem("apikey:inuse:#{service}", 1, key)
    $redis.rpush("apikey:available:#{service}", key)
  end
  def svcapi_showkeys(service)
    unless service == :all
      @inuse = $redis.lrange("apikey:inuse:#{service}", 0, -1)
      @available = $redis.lrange("apikey:available:#{service}", 0, -1)
      return { :inuse => @inuse, :available => @available }
    else
      @all = Hash.new
      $redis.keys('apikey:*').each do |service|
        if service =~ /:available:/
          begin
            @all[service.gsub('apikey:available:', '')][:available] = $redis.lrange(service, 0, -1)
          rescue
            @all[service.gsub('apikey:available:', '')] = Hash.new
            @all[service.gsub('apikey:available:', '')][:available] = $redis.lrange(service, 0, -1)
          end
        elsif service =~ /:inuse:/
          begin
            @all[service.gsub('apikey:inuse:', '')][:inuse] = $redis.lrange(service, 0, -1)
          rescue
            @all[service.gsub('apikey:inuse:', '')] = Hash.new
            @all[service.gsub('apikey:inuse:', '')][:inuse] = $redis.lrange(service, 0, -1)
          end
        end
      end
      return @all
    end
  end
  def svcapi_deletekey(service, key)
    begin
      $redis.lrem("apikey:inuse:#{service}", 1, key)
      $redis.lrem("apikey:available:#{service}", 1, key)
    rescue
    end
  end
  def svcapi_putkey(service, key)
    $redis.lpush("apikey:available:#{service}", key)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
gaptool-server-0.4.13 lib/helpers/services.rb
gaptool-server-0.4.12 lib/helpers/services.rb
gaptool-server-0.4.11 lib/helpers/services.rb
gaptool-server-0.4.10 lib/helpers/services.rb
gaptool-server-0.4.9 lib/helpers/services.rb
gaptool-server-0.4.8 lib/helpers/services.rb
gaptool-server-0.4.7 lib/helpers/services.rb
gaptool-server-0.4.6 lib/helpers/services.rb
gaptool-server-0.4.5 lib/helpers/services.rb
gaptool-server-0.4.4 lib/helpers/services.rb
gaptool-server-0.4.3 lib/helpers/services.rb
gaptool-server-0.4.2 lib/helpers/services.rb
gaptool-server-0.4.1 lib/helpers/services.rb
gaptool-server-0.4.0 lib/helpers/services.rb
gaptool-server-0.3.8 lib/helpers/services.rb
gaptool-server-0.3.7 lib/helpers/services.rb
gaptool-server-0.3.6 lib/helpers/services.rb
gaptool-server-0.3.3 lib/helpers/services.rb
gaptool-server-0.3.2 lib/helpers/services.rb