Jmeter通过BeanShell引用jar包的方式获取Redis服务的键值
1 新建一个Java工程
2.引入jar包
jedis-2.2.1.jar
commons-pool-1.6.jar
commons-lang-2.4.jar
3.新建Redisuntiles.java类
内容如下:
public class RedisUntils {
public static Jedis connRedisDB(String host,int port,String pwd)throws IOException{
//Jedis获取到的Redis数据在jedis里
Jedis jedis = new Jedis(host,port);
//判断密码是否为空,不为空时校验密码
if(StringUtils.isNotBlank(pwd)){
jedis.auth(pwd);
System.out.println("Redis服务连接成功!");
}
return jedis;
}
/**
*输出获取key与vlue,默认是第一个db
*@param host
*@param port
*@param pwd
*@param str
*@throws IOException
*/
public static void getRedisData(String host,int port,String pwd,int dbIndex,String str) throws IOException{
Jedis jedis=connRedisDB(host,port,pwd);
//到指定的数据库
jedis.select(dbIndex);