web123456

The use of hash method in RedisTemplate

  • package com;
  • import ;
  • import ;
  • import ;
  • import ;
  • import ;
  • import .Test;
  • import ;
  • import .factory.;
  • import .test.;
  • import .data.;
  • import .test.4.SpringRunner;
  • @RunWith(SpringRunner.class)
  • @SpringBootTest
  • public class SpringbootRedisAppMap {
  • /****
  • *
  • *redisTemplate operation Map
  • *
  • */
  • @Autowired
  • private RedisTemplate<String, String> redisTemplate;
  • /****
  • *
  • *Write to redis in a single way
  • */
  • @Test
  • public void MapRedis0() {
  • ().put("map1", "k1", "value1");
  • ().put("map1", "k2", "value2");
  • ().put("map1", "k3", "value3");
  • ().put("map1", "k4", "value4");
  • }
  • /****
  • *
  • *Write to redis in declaration
  • */
  • @Test
  • public void MapRedis() {
  • Map map=new HashMap<>();
  • ("k1", "value1");
  • ("k2", "value2");
  • ("k3", "value3");
  • ("k4", "value4");
  • ().putAll("map2", map);
  • }
  • /****
  • *Placed at the back (somewhat adds)
  • *
  • */
  • @Test
  • public void MapRedis2() {
  • ().putIfAbsent("map2", "k5", "value5");
  • }
  • /****
  • *
  • *Directly based on rediskeyDelete the map
  • */
  • @Test
  • public void MapRedis3() {
  • redisTemplate.delete("map1");
  • }
  • /****
  • *
  • *According to Rediskeyand hashkeyDelete as onevalue
  • */
  • @Test
  • public void MapRedis4() {
  • ().delete("map2", "k5");
  • }
  • /****
  • *
  • *According to RediskeyDetermine whether the hash exists and returnstrue, does not exist and returnsfalse
  • */
  • @Test
  • public void MapRedis5() {
  • ("map2");
  • (("map2"));
  • }
  • /****
  • *
  • *According to Rediskeyand mapkeyJudge hashkeyWhether exists, or not, returntrue, does not exist and returnsfalse
  • */
  • @Test
  • public void MapRedis6() {
  • ().hasKey("map2", "k4");
  • ().hasKey("map2", "k5");
  • (().hasKey("map2", "k4"));
  • (().hasKey("map2", "k5"));
  • }
  • /****
  • *
  • *Set expiration time for hash
  • */
  • @Test
  • public void MapRedis7() {
  • Map map=new HashMap<>();
  • ("k1", "value1");
  • ("k2", "value2");
  • ("k3", "value3");
  • ("k4", "value4");
  • ().putAll("map3", map);
  • ("map3", 1000, );
  • //NANOSECONDS Nanoseconds
  • //MICROSECONDS Microseconds
  • //MILLISECONDS milliseconds
  • //SECONDS seconds
  • //MINUTES Minutes
  • //HOURS Hours
  • //DAYS Day
  • }
  • /****
  • *
  • *Get the expiration time, according to the data type you store by default
  • */
  • @Test
  • public void MapRedis8() {
  • ("map3");
  • (("map3"));
  • }
  • /****
  • *
  • *Get expiration time, customize the time type
  • */
  • @Test
  • public void MapRedis9() {
  • ("map3", );
  • (("map3", ));
  • }
  • /****
  • *
  • *According to rediskey, and hashkeyGet the hashvalue
  • */
  • @Test
  • public void MapRedis10() {
  • ().get("map3", "k1");
  • ().get("map3", "k2");
  • ().get("map3", "k3");
  • ( ().get("map3", "k1"));
  • ( ().get("map3", "k2"));
  • ( ().get("map3", "k3"));
  • }
  • /****
  • *
  • *Get hash in the form of datavalue
  • */
  • @Test
  • public void MapRedis11() {
  • Collection<Object> keys = new ArrayList<>();
  • keys.add("k1");
  • keys.add("k2");
  • keys.add("k3");
  • ().multiGet("map3", keys);
  • (().multiGet("map3", keys));
  • }
  • /****
  • *
  • *According to RediskeyGetkeyAll key-value pairs of the corresponding hash table
  • */
  • @Test
  • public void MapRedis12() {
  • Map<Object, Object> entries = ().entries("map3");
  • (entries);
  • }
  • }