java中使用redis
文章目录
1.java代码
public class RedisTest01 {
public static void main(String[] args) {
// connect redis server
Jedis redis = new Jedis("127.0.0.1", 6379);
Map<String, String> map = new HashMap();
map.put("userName", "jack");
map.put("password", "123");
map.put("age", "12");
// 将map存入redis中
redis.hmset("myMap", map);
// 取出redis中的map进行遍历
Map<String, String> userMap = redis.hgetAll("myMap");
for (Map.Entry<String, String> item : userMap.entrySet()) {
System.out.println(item.getKey() + " : " + item.getValue());
}
}
}
2.输出
userName : jack
age : 12
password : 123
3.Hash存储类型最适合存储java中的Entity,用的比较多。。。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册⭐️ Admin快速开发: https://show.cool-admin.com/
赞 0⭐️ 官方文档: https://cool-js.com
赞 0⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld
赞 0