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());
相关推荐
小马过河R16 分钟前
真实场景:用户自建定时任务与推送提醒Agent-架构设计与可靠性实践
数据库·人工智能·agent·vibe coding·ai coding
鹤落晴春2 小时前
【MySQL】 | 两阶段提交、主从复制
运维·数据库·mysql
SelectDB2 小时前
中小企业数据仓库怎么选?按数据规模、BI 并发和国产化要求分三档
数据库
SelectDB2 小时前
数据仓库一年要花多少钱?云数仓、自建 Doris 成本拆解与 TCO 计算指南
数据库
码少女3 小时前
MySQL——复杂查询
数据库·mysql
txxzjmzlh4 小时前
JMeter简单介绍
jmeter
CoderYanger5 小时前
Java EE 进阶:11. SpringBoot 统一功能处理(第四弹):@ControllerAdvice 源码分析+案例代码
java·数据库·spring boot·后端·spring·java-ee·mybatis
TDengine (老段)5 小时前
TDengine 读缓存与 LAST 查询完全指南
大数据·数据库·物联网·缓存·时序数据库·tdengine·涛思数据
Decay__8 小时前
PostgreSQL 用户权限与安全 —— 角色体系、GRANT 授权、pg_hba.conf 认证、行级安全与审计
运维·数据库·sql·postgresql
goehou8 小时前
Redis 挂掉之后,数据能恢复到哪一步
redis·持久化·aof·rdb