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());
相关推荐
我是海浪18 小时前
DB2数据库:批量导入(Import)导出(Export)加载(Load)
数据库
霸王大陆18 小时前
《零基础学PHP:从入门到实战》教程-模块七:MySQL 数据库基础-4
数据库·mysql·php
i小白18 小时前
Sql Server 大批量数据迁移
服务器·数据库
Leon-Ning Liu18 小时前
【系列实验一】Oracle 19c RAC 安装(4个节点)
数据库·oracle
xuanloyer18 小时前
oracle从入门到精通--oracle体系结构
数据库·oracle
生产队队长18 小时前
Database:Linux环境中的Oracle修改密码
linux·数据库·oracle
Elseide艾思18 小时前
【数据速递】数字经济招聘数据(2012年至今)
数据库
叽里咕噜怪18 小时前
MySQL-主从复制实验详解
数据库·mysql
即将进化成人机18 小时前
巷陌店铺方法功能整理
数据库·mysql
菜萝卜子18 小时前
k8s 启动 postgresql 数据库
数据库·postgresql·kubernetes