多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] # 简介 redis中hashes类型可以看做具有String key和String value的map容器 ![](https://box.kancloud.cn/0f580a6fd220fee618b3d6f0a76d26db_545x367.png) # 命令行 ![](https://box.kancloud.cn/d42bb31e324ee22171eeb86ed4bbe46d_564x567.png) ![](https://box.kancloud.cn/504b8f29423f0664bd0e4e29ac3b2734_507x876.png) ![](https://box.kancloud.cn/dc90e50fbf4d071ad49c88b04f729506_439x430.png) # 代码 ## 存数据 ~~~ @Test public void testHash() { Jedis jedis = init(); jedis.hset("cart:user02","书","高性能mysql"); jedis.hset("cart:user02","笔","圆珠笔"); jedis.hset("cart:user02","画","八骏图"); jedis.close(); } ~~~ ## 查询 ~~~ @Test public void testSelect() { Jedis jedis = init(); Map<String, String> hgetAll = jedis.hgetAll("cart:user02"); Set<Map.Entry<String, String>> entrySet = hgetAll.entrySet(); for (Map.Entry<String, String> entry : entrySet) { System.out.println(entry.getKey() + ":" + entry.getValue()); } } ~~~ ## 自增 ~~~ Jedis jedis = init(); jedis.hset("cart:user", "价格1", "1"); jedis.hset("cart:user", "价格2", "1"); //给价格1的值+1 jedis.hincrBy("cart:user", "价格1", 1); jedis.close(); ~~~ ## 删除 ~~~ Jedis jedis = init(); jedis.hdel("cart:user", "价格1"); jedis.close(); ~~~