scala链接redis报错.
用代码块功能插入代码,请勿粘贴截图
配置文件:
工具类:
package demo04
import java.util.Properties
import org.apache.commons.pool2.impl.GenericObjectPoolConfig
import redis.clients.jedis.JedisPool
object RedisClient {
val prop =new Properties ()
//加载配置文件
prop.load(
this.getClass.getClassLoader.getResourceAsStream("sprakstream.properties"))
val redisHost:String =prop.getProperty("jedis.host")
val redisPort:String =prop.getProperty("jedis.port")
val redisTimeout:String =prop.getProperty("jedis.max.wait.millis")
lazy val pool =new JedisPool(new GenericObjectPoolConfig(),
redisHost,redisPort.toInt,redisTimeout.toInt)
lazy val hook =new Thread{
override def run = {
println("Execute hook thread:"+this)
pool.destroy()}
}
}
主类:
package demo04
import redis.clients.jedis.Jedis
object dome01 {
def main(args: Array[String]): Unit = {
val jedis : Jedis= RedisClient.pool.getResource ()
//指定数据库
jedis.select(1)
// jedis.hincrBy("orderTotalKey","key2",3)
jedis.incrBy("totalKey",4)
RedisClient.pool.returnResource(jedis)
}
}
运行结果及报错内容
我想要达到的结果
想要成功链接redis