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());
相关推荐
数据皮皮侠1 小时前
区县政府税务数据分析能力建设DID(2007-2025)
大数据·数据库·人工智能·信息可视化·微信开放平台
请叫我阿杰2 小时前
Ubuntu系统安装.NET SDK 7.0
数据库·ubuntu·.net
q***82913 小时前
如何使用C#与SQL Server数据库进行交互
数据库·c#·交互
盖世英雄酱581364 小时前
commit 成功为什么数据只更新了部分?
java·数据库·后端
煎蛋学姐4 小时前
SSM网上旅游订票服务系统10r27(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·ssm 框架·网上旅游订票系统·旅游服务数字化
海南java第二人5 小时前
数据库范式详解:从冗余到规范的升华之旅
数据库·oracle·ffmpeg
hyx0412195 小时前
mysql第5次作业---hyx
数据库·mysql
Daniel大人5 小时前
关于sqlite
数据库·sqlite
nsjqj6 小时前
MySQL数据库:表的增删改查 [CRUD](进阶)【一】
数据库·mysql