Template code for configuring RedisClient in spark

Hello everyone: For the template code for configuring the redis client in spark, please refer to

import org.apache.commons.pool2.impl.GenericObjectPoolConfig

import redis.clients.jedis.JedisPool


object RedisClient extends Serializable {
  val redisHost = "192.168.16.100"
  val redisPort = 6379
  val redisTimeout = 30000
  lazy val pool = new JedisPool(new GenericObjectPoolConfig(), redisHost, redisPort, redisTimeout)


  lazy val hook = new Thread {
    override def run = {
      println("Execute hook thread: " + this)
      pool.destroy()
    }
  }
  sys.addShutdownHook(hook.run)
}

Note: If the jar is missing, you need to import commons-pool2-2.2.jar and jedis-2.6.1.jar

Guess you like

Origin blog.csdn.net/zhaoxiangchong/article/details/78379883