zoukankan      html  css  js  c++  java
  • C# 当net遇到Redis,Redis初步使用

    1、引入nuget包

    搜索 servicestackredis 安装redis包

     2、连接redis服务器,读取以及存储

    public static ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient("127.0.0.1", 6379, "mimashi123.");
            // GET: Home
            public ActionResult Index()
            {            
                //读取
                string name = client.Get<string>("name");
                string pwd = client.Get<string>("password");
    
                //存储
                client.Set<string>("name1", "admin1");
                client.Set<string>("password1", "admin123");
    
    
                List<Phone> phoneList = new List<Phone>();
                Phone p = new Phone("小米5", "小米", "3500");
                Phone p1 = new Phone("小米2A", "小米", "2500");
                Phone p2 = new Phone("荣耀20Pro", "华为", "3500");
                phoneList.Add(p);
                phoneList.Add(p1);
                phoneList.Add(p2);
    
                client.Set<List<Phone>>("phoneList", phoneList);
    
                List<Phone> pList = client.Get<List<Phone>>("phoneList");
    
    
    
                return View();
            }

     

    实践思路:例如手机信息表,可以把整个表的数据以集合的形式存入redis 优化读取速度,当某个手机信息发生改变时,修改数据库信息,变更redis内的值。

    参考地址:https://www.cnblogs.com/wangjifeng23/p/9105165.html

  • 相关阅读:
    window.location.reload();页面实现跳转和刷新
    vue自定义指令--directive
    1019 数字黑洞
    1018 锤子剪刀布
    1017 A除以B
    1016 部分A+B
    1015 德才论
    1014 福尔摩斯的约会
    1013 数素数
    1012 数字分类
  • 原文地址:https://www.cnblogs.com/JoeYD/p/13958646.html
Copyright © 2011-2022 走看看