zoukankan      html  css  js  c++  java
  • redis demo

    方法hset(String key,String field,String value),hmset(String key, Map<String,String> hash),hgetAll()

    hash结构(key value)

    业务场景:当信物无感时间超过一定时间 就再次出现

    实现:

     用redis 存储无感信物去exclude: 

    //1.批量获取用户的无感信物列表:

    (判断无感信物有效期是否超过):
    Map<String, String> userGiftList = giftCacheFacade.getUser(userId);
    (内置方法:Map<String, String> hash = redisClientTemplate.hgetAll(key))
    Map<String, String> newUserGiftList = Maps.newHashMap();
    //用户的无感信物id列表

    List<Integer> excludeGiftIds = Lists.newArrayList();
    for (String giftIdStr : userGiftList.keySet()) {
    String giftExpireTime = userGiftList.get(giftIdStr);
    if (System.currentTimeMillis() < Long.valueOf(giftExpireTime)) {
    newUserGiftList.put(giftIdStr, giftExpireTime);
    excludeGiftIds.add(Integer.valueOf(giftIdStr));
    }
    }

    //2.更新缓存
    newUserGiftList.forEach((k, v) -> giftCacheFacade.setUser(userId, Integer.parseInt(k), Long.parseLong(v)));
    (内置方法:redisClientTemplate.hset(userId, giftId + "", expireTime + ""))
  • 相关阅读:
    python字典类型
    python集合类型
    python元组类型
    python列表类型
    Python中的序列操作
    python字符串格式化输出
    python可变对象和不可变对象的解释
    Python数值类型
    Python循环结构用法
    python if条件判断语句
  • 原文地址:https://www.cnblogs.com/yzf666/p/9680898.html
Copyright © 2011-2022 走看看