jmeter后置处理器BeanShell PostProcessor连接redis获取value

来源:互联网 发布:淘宝买的东西下架了 编辑:程序博客网 时间:2024/06/06 00:08

1、写好java文件RedisCon.java保存在指定路径

package connectredis;
import redis.clients.jedis.Jedis;


public class RedisCon {
private static Jedis jredis;
/**

* @param host 地址
* @param port 端口
* @return 链接对象
*/
        public static Jedis connectJredis(String host,int port){
        try {
        jredis=new Jedis(host, port, 5000);
} catch (Exception e) {
// TODO: handle exception
}
        return jredis;
        }

        /**
         * 断开连接
         */
        public static void closeJredis() {
                if (jredis != null) {
//                        System.out.println("** 断开与服务器的连接 **");
                        jredis.quit();
                }
        }

        public static void main(String[] args) throws Exception {
        }
        }

2、在http请求添加后置处理器BeanShell PostProcessor,配置如下


1、其中source填写RedisCon.java文件全路径,pkey为从http请求获取的变量值

2、tkey为需要从redis取值的键值,最后通过RedisCon.connectJredis("${redishost}",6379).get(tKey)将value值取出,放至变量code中




1 0