(jmeter笔记)Beanshell取样器,管理redis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import redis.clients.jedis.Jedis; import org.apache.commons.lang3.StringUtils; import java.util.Map; import java.util.logging.Logger; public class RedisExample { private static final Logger log = Logger.getLogger(RedisExample. class .getName()); public static void main(String[] args) { // Redis服务器地址 String host = "10.0.0.1" ; // Redis服务端口号 int port = 16379 ; // Redis密码 String password = "******" ; // 获取Redis键值 String key = "EXAM_DATA_ANALYSIS_FILES${ksfxid}" ; try (Jedis jedis = new Jedis(host, port)) { // 判断密码是否为空,不为空时校验密码 if (StringUtils.isNotBlank(password)) { jedis.auth(password); } // 定位DB jedis.select( 10 ); // 获取哈希key对应的值 Map<String, String> gethash = jedis.hgetAll(key); log.info( "==========>>>>>>>>>:" + key); log.info( "gethash is :" + gethash); log.info( "gethash keys are :" + gethash.keySet()); log.info( "gethash values are :" + gethash.values()); // 将结果存储到变量中(假设vars是一个Map对象) Map<String, Object> vars = new HashMap<>(); vars.put( "redisKey" , gethash.keySet().toString()); vars.put( "redisValues" , gethash.values().toString()); log.info( "Stored keys and values in vars" ); } catch (Exception e) { log.severe( "Error occurred: " + e.getMessage()); } finally { log.info( "Closed jedis connection" ); } } } |
结合下图,可见上面表示的意思,RD用的HASH类型,
1 | Redis键值:左侧红框内的内容,不懂创建就知道了; |
1 | jedis.select():定位索引,见配置用的哪个库; |
1 | jedis.hgetAll():读取所有key,见右侧Key列 |
本文来自博客园,作者:茫茫人海中的一颗沙尘,转载请注明原文链接:https://www.cnblogs.com/worldbugMsg/p/18643161
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构