Jmeter连接Redis服务缓存

1、添加线程组->Sampler->BeanShell Sampler,加入以下内容:

import redis.clients.jedis.Jedis;
import org.apache.commons.lang3.StringUtils;

String host = "192.168.100.171";    //服务器地址
int port = 6379;                //端口号
String password = "";            //redis密码
int index = 1;                    //redis db
String key = "APP:LOGIN:TOKEN:${token1}";
String value = "{\"avatarUrl\":\"https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJE0X0a608HBicwVpnJRBQnv7Hw8E1M5lQByn4EVGpp2JMpibUE3ow8A5Qcgd8TTSXvZaudibeMnYLAw/132\",\"gender\":\"2\",\"id\":\"${token1}\",\"nickname\":\"小郗\",\"openid\":\"o8-Z_9gfapFW66QhtWRPtiL7HFQU\"}";

Jedis jedis = new Jedis(host, port);
if(StringUtils.isNotBlank(password)){
    jedis.auth(password);
  }
jedis.select(index);    //选择redis db
jedis.set(key, value);    //插入key, value


token = jedis.get(key);    //获取key的值
vars.put("token",token);    //将key的值保存为变量
//log.info("token:"+token);

 

2、添加Debug Sampler,查看运行结果

 

posted @ 2018-12-20 17:53  小郗测试  阅读(2155)  评论(0编辑  收藏  举报