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 + ""))
redis demo的更多相关文章
- asp.net core上使用Redis demo
整体思路:(1.面向接口编程 2.Redis可视化操作IDE 3.Redis服务) [无私分享:ASP.NET CORE 项目实战(第十一章)]Asp.net Core 缓存 MemoryCache ...
- linux下小试redis demo
先启动 redis-server /etc/redis/redis.conf package com.test; import java.util.ArrayList; import java.ut ...
- python redis demo
上代码,redis-demo #!/usr/bin/env python #_*_ coding:UTF-8 _*_ import redis ####配置参数 host = '192.168.0.1 ...
- springboot( 三)redis demo
redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结构,例如hashes, lists, sets等,同时支持数据持久化.除此之外,Red ...
- Spring Data Redis简介以及项目Demo,RedisTemplate和 Serializer详解
一.概念简介: Redis: Redis是一款开源的Key-Value数据库,运行在内存中,由ANSI C编写,详细的信息在Redis官网上面有,因为我自己通过google等各种渠道去学习Redis, ...
- Redis分布式缓存 教程以及DEMO
原文地址:http://blog.csdn.net/qiujialongjjj/article/category/1800171 redis demo源码下载:http://download.csdn ...
- C# Redis Server分布式缓存编程 --网络转载
这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...
- 半小时快速了解redis,基于ubuntu 12.04 + redis 2.8.9
一.什么是redis ? 其官方介绍是: Redis is what is called a key-value store, often referred to as a NoSQL databas ...
- C# Redis Server分布式缓存编程(二)
在Redis编程中, 实体和集合类型则更加有趣和实用 namespace Zeus.Cache.Redis.Demo { public class Person { public int Id { g ...
随机推荐
- luoguP1540 机器翻译 题解(NOIP2010)
P1540 机器翻译 题目 #include<iostream> #include<cstdlib> #include<cstdio> #include<c ...
- Memory layout of x86_64 in Linux
Blue : User Space 128TBRed : Kernel Space 512MBThe rest of the address space goes to various parts o ...
- 50.Maximal Square(最大正方形)
Level Medium 题目描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square conta ...
- wireshark抓取本地回环及其问题 转摘:http://www.cnblogs.com/luminji/p/3503464.html
一:The NPF driver isn’t running 这个错误是因为没有开启NPF服务造成的. NPF即网络数据包过滤器(Netgroup Packet Filter,NPF)是Winpcap ...
- node单线程
const fs=require('fs'); console.time('timer'); fs.stat('./1.txt',(err,stats)=>{ //console.log(sta ...
- until 循环语句
- tensorflow 版本的mask rcnn 实践
1. https://www.jianshu.com/p/27e4dc070761 (tensorflow object detection API/Mask RCNN)
- go语言从例子开始之Example20.错误处理
Go 语言使用一个独立的·明确的返回值来传递错误信息的.这与使用异常的 Java 和 Ruby 以及在 C 语言中经常见到的超重的单返回值/错误值相比,Go 语言的处理方式能清楚的知道哪个函数返回了错 ...
- 获得本机物理ip地址mac
https://blog.csdn.net/guang670248515/article/details/81040797 文章来源:https://blog.csdn.net/kingepoch/a ...
- 力扣 ——3Sum python (三数之和)实现
题目描述: 中文: 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 英文: Give ...