• Jmeter redis连接测试


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

    1. import redis.clients.jedis.*;
    2. import java.io.IOException;
    3. import java.util.HashSet;
    4. import java.util.Set;
    5. /**
    6. * 单机版的Jedis连接池的用法
    7. */
    8. public class RedisClient {
    9. public static Jedis GetRedisClient(String ip, int port, String password, int database) throws IOException {
    10. Integer maxTotal = 60000; // 最大连接数
    11. Integer maxIdle = 1000; // 最大空闲数
    12. Integer MinIdle = 1; //
    13. Integer maxWaitMillis = 3000; // 超时时间
    14. JedisPoolConfig poolConfig = new JedisPoolConfig();
    15. poolConfig.setMaxTotal(maxTotal);
    16. poolConfig.setMaxIdle(maxIdle);
    17. poolConfig.setMinIdle(MinIdle);
    18. JedisPool jedisPool = new JedisPool(poolConfig, ip, port, 2000, password, database);
    19. // 从连接池中获取jedis对象
    20. Jedis jedis = jedisPool.getResource();
    21. return jedis;
    22. }
    23. /**
    24. * 集群的Jedis连接池的用法
    25. */
    26. public static JedisCluster getRedisCluster(String clusterNodes, String password) {
    27. JedisCluster jedisCluster = null;
    28. Integer maxTotal = 60000; // 最大连接数
    29. Integer maxIdle = 1000; // 最大空闲数
    30. Integer maxWaitMillis = 3000;
    31. //分割出集群节点
    32. String[] cNodes = clusterNodes.split(",");
    33. Set nodes = new HashSet<>();
    34. for (String node : cNodes) {
    35. String[] ipAndPort = node.split(":");
    36. nodes.add(new HostAndPort(ipAndPort[0], Integer.parseInt(ipAndPort[1])));
    37. }
    38. // 配置连接池
    39. JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    40. jedisPoolConfig.setMaxTotal(maxTotal);
    41. jedisPoolConfig.setMaxIdle(maxIdle);
    42. jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
    43. // 连接Redis集群
    44. jedisCluster = new JedisCluster(nodes, 3000, 3000, 5, password, jedisPoolConfig);
    45. return jedisCluster;
    46. }
    47. }

    在jmeter beanshell

    1. import cn.oscar.common.RedisClient;
    2. import redis.clients.jedis.Jedis;
    3. import redis.clients.jedis.JedisPool;
    4. import redis.clients.jedis.JedisPoolConfig;
    5. String nodes = "IP";
    6. String password = "passwd";
    7. String key = "redis_key";
    8. Jedis testJedis = RedisClient.GetRedisClient(nodes,6379,password,0);
    9. value=testJedis.get(key);
    10. testJedis.close();
    11. log.info("========redis返回值=============="+value.toString());

  • 相关阅读:
    cell delay和net delay
    初始多线程
    Centos 搭建MQTT
    挖掘数据价值,华为云大数据BI解决方案有绝招
    唯众中职Web前端专业解决方案
    JavaSE | 初始Java(十) | 继承和多态
    杭电oj 2059 龟兔赛跑 C语言
    第三十章 管理许可(三)
    misc类设备驱动0——板载蜂鸣器驱动测试
    多数互联网人对2021年终奖不抱期待
  • 原文地址:https://blog.csdn.net/oscarli/article/details/137958510