Jmeter redis连接测试

Jmeter连接redis获取数据,一直连不上报错。最后只能通过java代码连接测试,最后只能自己动手。

java 复制代码
import redis.clients.jedis.*;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;


/**
 * 单机版的Jedis连接池的用法
 */
public class RedisClient {

    public static Jedis GetRedisClient(String ip, int port, String password, int database) throws IOException {
        Integer maxTotal = 60000;        // 最大连接数
        Integer maxIdle = 1000;            // 最大空闲数
        Integer MinIdle = 1;            //
        Integer maxWaitMillis = 3000;       // 超时时间
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(maxTotal);
        poolConfig.setMaxIdle(maxIdle);
        poolConfig.setMinIdle(MinIdle);
        JedisPool jedisPool = new JedisPool(poolConfig, ip, port, 2000, password, database);

        // 从连接池中获取jedis对象
        Jedis jedis = jedisPool.getResource();

        return jedis;

    }

    /**
     * 集群的Jedis连接池的用法
     */
    public static JedisCluster getRedisCluster(String clusterNodes, String password) {
        JedisCluster jedisCluster = null;
        Integer maxTotal = 60000;        // 最大连接数
        Integer maxIdle = 1000;            // 最大空闲数
        Integer maxWaitMillis = 3000;
        //分割出集群节点
        String[] cNodes = clusterNodes.split(",");
        Set<HostAndPort> nodes = new HashSet<>();
        for (String node : cNodes) {
            String[] ipAndPort = node.split(":");
            nodes.add(new HostAndPort(ipAndPort[0], Integer.parseInt(ipAndPort[1])));
        }

        // 配置连接池
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(maxTotal);
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);


        // 连接Redis集群
        jedisCluster = new JedisCluster(nodes, 3000, 3000, 5, password, jedisPoolConfig);

        return jedisCluster;

    }

   }

在jmeter beanshell

java 复制代码
import cn.oscar.common.RedisClient;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

String nodes = "IP";
String password = "passwd";
String key = "redis_key";

Jedis testJedis = RedisClient.GetRedisClient(nodes,6379,password,0);


value=testJedis.get(key);
testJedis.close();


log.info("========redis返回值=============="+value.toString());
相关推荐
会飞的架狗师3 小时前
【MySQL体系】第8篇:MySQL集群架构技术详解
数据库·mysql·架构
yangchanghua1113 小时前
[记录]一个30秒的sql,我是怎么把它改到0.5秒的
数据库·sql·性能优化
行者游学4 小时前
ETCD 集群备份与恢复
数据库·etcd
行者游学4 小时前
ETCD 学习使用
数据库·学习·etcd
代码程序猿RIP4 小时前
【Etcd 】Etcd 详解以及安装教程
linux·数据库·etcd
tqs_123455 小时前
创建es索引
数据库·es
间彧5 小时前
Mysql优化指南:善用覆盖索引,提升查询效率
数据库
间彧6 小时前
MySQL优化指南:执行计划type字段详解
数据库
合作小小程序员小小店6 小时前
web网页,在线%抖音,舆情%分析系统demo,基于python+web+echart+nlp+知识图谱,数据库mysql
数据库·python·自然语言处理·flask·nlp·echarts·知识图谱