package SparkStreaming
import java.util
import redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig}
/**
* Created by 古城小巷少年 on 2020-01-03 15:53
* jedis操作redis
*/
object JedisTest {
private val conf = new JedisPoolConfig()
// 最大连接数
conf.setMaxTotal(20)
// 最大空闲连接数
conf.setMaxIdle(10)
// 当调用borrow Object方法时,是否进行有效性检查
conf.setTestOnBorrow(true)
// 10 000代表超时时间10秒
private val pool = new JedisPool(conf, "192.168.152.102", 6379, 10000,"123")
def getConnection()={
pool.getResource
}
def main(args: Array[String]): Unit = {
//
val conn: Jedis = JedisTest.getConnection()
val r1: String = conn.get("zhaolanlei")
println(r1)
conn.incrBy("zhaolan",30)
val r2: String = conn.get("zhaolan")
println(r2)
conn.set("lucas","24")
val r3: String = conn.get("lucas")
println(r3)
println("~~~~~~~~~~~~~~~~~")
val keys: util.Set[String] = conn.keys("*")
import scala.collection.JavaConversions._
for(k <- keys){
println(k + ":" + conn.get(k))
}
}
}