Sha256: ed31c0997a516978cb9b3d3b1c248995baf90d23754221bc574fff5454f9337e

Contents?: true

Size: 946 Bytes

Versions: 6

Compression:

Stored size: 946 Bytes

Contents

require 'forwardable'
module GameMachine
  module DataStores
    class Redis
      extend Forwardable

      def connect
        @pool = RedisLib::JedisPool.new(RedisLib::JedisPoolConfig.new, "localhost");
      end

      def delete(key)
        query(:del,key)
      end

      def get(key)
       query(:get,key)
      end

      def set(key,value)
        query(:set,key, value)
      end

      def query(command,key,value=nil)
        jedis = @pool.get_resource
        case command
        when :get
          jedis.get(key)
        when :set
          res = jedis.set(key,value)
          res == 'OK' ? true : false
        when :del
          res = jedis.del(key)
          res == 1 ? true : false
        end
      rescue RedisLib::JedisConnectionException => e
        @pool.return_broken_resource(jedis)
      ensure
        @pool.return_resource(jedis)
      end

      def shutdown
        @pool.destroy
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
game_machine-1.0.4 lib/game_machine/data_stores/redis.rb
game_machine-1.0.2 lib/game_machine/data_stores/redis.rb
game_machine-0.0.11 lib/game_machine/data_stores/redis.rb
game_machine-0.0.10 lib/game_machine/data_stores/redis.rb
game_machine-0.0.9 lib/game_machine/data_stores/redis.rb
game_machine-0.0.8 lib/game_machine/data_stores/redis.rb