惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
小众软件
小众软件
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - 聂微东
Recent Announcements
Recent Announcements
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
云风的 BLOG
云风的 BLOG
量子位
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
博客园 - 司徒正美
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享

博客园 - CHHC

从服务端到桌面端:Go + HTML 多端交付方案 跨平台桌面应用(内嵌 Web 界面 + Go RESTful API 服务) Dify 网页爬虫 Ai常用工具 Dify公司内部知识库权限隔离 智能体:OA行政助手 dify4: test-doc dify3: test-api dify2: test-image dify1: test-local-ollama 访问本地大模型 docker + dify + ollma 安装与配置 dify使用 eSIM SGP32 IPAd 适配移远EC200A OpenCPU 公钥解析 eSIM SGP32 自建符合GSMA规范的eIM平台(支持SGP32及SGP22卡接入) eSIM SGP32 eIM GSMA转码器(支持net及java) eSIM SGP32 证书 eSIM SGP32 生成eUICC所需的配置数据 eSIM SGP32 EuiccPackage包eimSignature和euiccSignEPR生成及校验 eSIM SGP32/SGP22 EUICC.SDK - IPAd RTSPShape-包含服务端及客户端 树莓派安装与配置 NetCore树莓派桌面应用程序 C#解析TLV数据(der -> asn1) golang 项目依赖备份 SGP32笔记 SoftSIM - swSIM eSIM SGP.22 LPA程序开发 - 协议解析 eSIM SGP.22 LPA程序开发 - 实现功能 PGP文件加解密
SQLiteRedis - 静动态数据联合使用
CHHC · 2025-10-17 · via 博客园 - CHHC

SQLite:存储静态数据,Redis存储动态数据,当点位数据发送变化时更新Redis数据,查询时:联合查询,返回DTO

image

using SQLiteRedis.redis;
using SQLiteRedis.Util;
using SQLiteRedis.Util.model;

namespace SQLiteRedis
{
    internal class Program
    {
        static void Main(string[] args)
        {
            FreeSqlUtil.InitDB();
            RedisUtil.Init("127.0.0.1", 6379, "", 0);

            InitData();

            // 单条执行
            Task.Run(() => TaskQuery());
            Task.Run(() => TaskUpdate());

            Console.ReadLine();
        }

        static async Task InitData()
        {
            var lstPoint = FreeSqlUtil.AllEquipPoint("78e4ea7c-2862-4f19-87ff-ae45b888810e").Result;
            foreach (var item in lstPoint)
            {
                var pointCode = item.PointCode; 
                if (!RedisUtil.ExistKey(pointCode))
                {
                    var p = new Util.model.redis.EquipPoint() { PointCode = pointCode, ItemTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; 
                    RedisUtil.Set(Util.RedisKey.StoreKey_EquipPoint(pointCode), p);
                }
            }
        }

        static async Task TaskQuery()
        {
            var keys = RedisUtil.GetKeys(Util.RedisKey.EquipPoint);

            while (true)
            {
                var lstPoint1 = await FreeSqlUtil.AllEquipPoint("78e4ea7c-2862-4f19-87ff-ae45b888810e");
                var lstPoint2 = await RedisUtil.GetBatchAsync<Util.model.redis.EquipPoint>(keys);
                 
                var resultDtoList = (from d1 in lstPoint1
                                     join d2 in lstPoint2 on d1.PointCode equals d2.PointCode into alldata
                                     from d in alldata.DefaultIfEmpty()
                                     select new EquipPointDto
                                     {
                                         Id = d1.Id,
                                         PointCode = d1.PointCode,
                                         EquipCode = d1.EquipCode,
                                         PointName = d1.PointName,
                                         ItemValue = d.ItemValue,
                                         ItemTime = d.ItemTime
                                     }).ToList();

                foreach (var item in resultDtoList)
                {
                    Console.WriteLine($"ID:{item.Id}, PointCode:{item.PointCode}, EquipCode:{item.EquipCode}, PointName:{item.PointName},ItemValue:{item.ItemValue}, ItemTime:{item.ItemTime}");
                }

                await Task.Delay(10000);
            }
        }

        static async Task TaskUpdate()
        {
            while (true)
            {
                await Task.Delay(5000);
                var lstPoint = await FreeSqlUtil.AllEquipPoint("78e4ea7c-2862-4f19-87ff-ae45b888810e");
                foreach (var item in lstPoint)
                {
                    var pointCode = item.PointCode;
                    var redisCode = Util.RedisKey.StoreKey_EquipPoint(pointCode);
                    var p = RedisUtil.Get<Util.model.redis.EquipPoint>(redisCode, out bool status);
                    if (null == p) p = new Util.model.redis.EquipPoint(); 
                    p.ItemTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    RedisUtil.Set(redisCode, p); 
                }
            }
        }
    }
}