Sha256: dc7e7fec8a1c2507f04ced30694027d13346bddb34857164c44fc34a676e9d70

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'java'
require 'jedis-2.7.3.jar'
require 'commons-pool2-2.4.2.jar'

java_package 'jp.gr.java_conf.ogibayashi.norikra.udf'

class Redis  # FQDN: org.example.yourcompany.norikra.udf.MyUDF1
  
  def self.connect
    begin
      Java::redis.clients.jedis.JedisPool.new(Java::redis.clients.jedis.JedisPoolConfig.new, "localhost")
    rescue
      warn $! if @logger
    end
  end
  
  def self.pool
    @@pool || self.connect
  end
  
  @@pool = self.connect
  
  java_signature 'public long incr(String)'
  def self.incr(key)
    jedis = pool.getResource()
    ret = jedis.incr(key)
    jedis.close()
    ret 
  end
  
  java_signature 'public long incrby(String, long)'
  def self.incrby(key, value)
    jedis = pool.getResource()
    ret = jedis.incrBy(key, value)
    jedis.close()
    ret
  end

  # set, get, del  are prefixed 'r' to avoid reserved words.
  
  java_signature 'public String rset(String, String)'
  def self.rset(key, value)
    jedis = pool.getResource()
    ret = jedis.set(key, value)
    jedis.close()
    ret 
  end

  java_signature 'public String rget(String)'
  def self.rget(key)
    jedis = pool.getResource()
    ret = jedis.get(key)
    jedis.close()
    ret
  end

  java_signature 'public long rdel(String)'
  def self.rdel(key)
    jedis = pool.getResource()
    ret = jedis.del(key)
    jedis.close()
    ret 
  end
  

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
norikra-udf-redis-0.0.1-java lib/esper_plugin/redis.rb