原因是redis中的hmset命令合并新增的和原先的(重复的覆盖),而不是重置,需要先del后再新增
Redis Map 增长问题
原因:
redis中的hmset命令合并新增的和原先的(重复的覆盖),而不是重置,需要先del后再新增。下面是验证过程:
redis命令验证:
1 2 3 4 5 6 7 8 9 10 11
| 127.0.0.1:0>hmset TestMap test1 "11111" test2 "22222" "OK"
127.0.0.1:0>hget TestMap test1 "11111"
127.0.0.1:0>hmset TestMap test2 "22222" "OK"
127.0.0.1:0>hget TestMap test1 "11111"
|
java验证
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
| import com.ems.dsp.util.RedisClient; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner;
import java.util.HashMap; import java.util.Map;
@RunWith(SpringRunner.class) @SpringBootTest public class JedisTest {
@Autowired private RedisClient redisClient;
@Test public void redisDemo(){ String key = "TestMap";
Map<String,String> map1 = new HashMap<>(); map1.put("test1","11111"); map1.put("test2","22222"); redisClient.hmset(key, map1); System.out.println("########################################################"); System.out.println(redisClient.hmget(key, "test1")); System.out.println("########################################################");
Map<String,String> map2 = new HashMap<>(); map2.put("test2","22222"); redisClient.hmset(key, map2); System.out.println("********************************************************"); System.out.println(redisClient.hmget(key, "test1")); System.out.println("********************************************************"); } }
|
此为博主副博客,留言请去主博客,转载请注明出处:https://www.baby7blog.com/myBlog/134.html