Пример #1
0
 public static void AddRangeToList(string listId, List <string> values)
 {
     using (RedisClient client = GetClient())
     {
         client.AddRangeToList(listId, values);
     }
 }
Пример #2
0
 /// <summary>
 /// 存储List类型数据指定key值
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public void SetList(string key, List <string> value)
 {
     using (RedisClient redisclient = new RedisClient(RedisPath, RedisPort, "123456"))
     {
         redisclient.AddRangeToList(key, value);
     }
 }
Пример #3
0
 /// <summary>
 /// 添加多个value 到现有List
 /// </summary>
 /// <param name="key"></param>
 /// <param name="values"></param>
 public void AddRangeToList(string key, List <string> values)
 {
     using (RedisClient redisClient = GetRedisClient())
     {
         redisClient.AddRangeToList(key, values);
     }
 }
Пример #4
0
 public void AddOnList(string key, List <string> list)
 {
     using (RedisClient redisClient = this.redis.GetRedisClient())
     {
         redisClient.AddRangeToList(key, list);
     }
 }
Пример #5
0
 public static void addKeyStringValueListStringToList(String key, List <String> listDataSource)
 {
     using (RedisClient redisClient = new RedisClient(host, port))
     {
         redisClient.AddRangeToList(key, listDataSource);
         redisClient.Dispose();
     }
 }
Пример #6
0
 /// <summary>
 /// 将多个值添加至 redis  List中
 /// </summary>
 /// <param name="list"></param>
 /// <param name="items"></param>
 /// <param name="seconds"></param>
 public void AddRangeToList(string list, List <string> items, int seconds)
 {
     //using (IRedisTransaction trans = redisCli.CreateTransaction())
     //{
     //    try
     //    {
     //        trans.QueueCommand(r => r.AddRangeToList(list, items));
     //        trans.QueueCommand(r => r.ExpireEntryAt(list, dateTime));
     //        trans.Commit();
     //    }
     //    catch
     //    {
     //        trans.Rollback();
     //    }
     //}
     redisCli.AddRangeToList(list, items);
     redisCli.Expire(list, seconds);
 }
Пример #7
0
        //0 8 16 23//暂停使用。
        private void plNewMethod()
        {
            string curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:10:00");

            this.richTextBox3.Invoke(new ThreadStart(delegate()
            {
                richTextBox3.Text           = "【评论】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                richTextBox3.SelectionStart = richTextBox3.TextLength;
                richTextBox3.ScrollToCaret();
            }));
            writeR(this.richTextBox3, "【评论】下次时间:" + curenttime + "...");

            while (true)
            {
                if (DateTime.Now >= DateTime.Parse(curenttime))
                {
                    try
                    {
                        this.richTextBox3.Invoke(new ThreadStart(delegate()
                        {
                            if (this.richTextBox3.Lines.Length > 40)
                            {
                                richTextBox3.Clear();
                            }
                            richTextBox3.Text           = "【评论】采集......请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                            richTextBox3.SelectionStart = richTextBox3.TextLength;
                            richTextBox3.ScrollToCaret();
                        }));
                        writeR(this.richTextBox3, "开始查询URL...");

                        string    sqlStr = "select '{\"Urls\": \"'+Urls+'\",\"urlweb\":\"'+Urlweb+'\",\"urlleibie\":\"'+Urlleibie+'\"}' from URLDATA";
                        DataTable dt     = db.selectDatas(sqlStr);

                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        writeR(this.richTextBox3, "URL插入redis 共有:" + urlList.Count + "...");
                        RedisClient client = new RedisClient("117.122.192.50", 6479);
                        client.AddRangeToList("comment_spider:start_urls", urlList);

                        writeR(this.richTextBox3, "成功,等待下次...");
                        curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:10:00");
                        writeR(this.richTextBox3, "【评论】下次时间:" + curenttime + "...");
                    }
                    catch (Exception ecppp)
                    {
                        writeR(this.richTextBox3, "报错:" + ecppp.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(1000 * 60 * 10);
                }
            }
        }
Пример #8
0
 public static void AddEntitiesToList <T>(string key, IEnumerable <T> entities)
 {
     using (var client = new RedisClient(Host))
     {
         List <string> values = new List <string>();
         foreach (var item in entities)
         {
             string val = JsonConvert.SerializeObject(item);
             values.Add(val);
         }
         client.AddRangeToList(key, values);
     }
 }
Пример #9
0
        static void simpleRedisGetSet()
        {
            string      host        = "localhost";
            string      elementKey  = "testKeyRedis";
            RedisClient redisclient = new RedisClient(host);

            redisclient.Remove(elementKey);
            var storeMembers = new List <string> {
                "asd", "dsd", "bb"
            };

            // storeMembers.ForEach(x=>redisclient.AddItemToList(elementKey,x));

            redisclient.AddRangeToList(elementKey, storeMembers);
            var members = redisclient.GetAllItemsFromList(elementKey);
            var list    = redisclient.Lists[elementKey];

            list.Clear();
            var  ser    = new ObjectSerializer();
            bool result = redisclient.Set <byte[]>(elementKey, ser.Serialize(storeMembers));

            if (result)
            {
                var resultlist = ser.Deserialize(redisclient.Get <byte[]>(elementKey));
            }
            members.ForEach(s => Console.WriteLine("list:" + s));
            //   Console.WriteLine("index2:"+redisclient.GetItemFromList(elementKey,1));
            //if (redisclient.Get<string>(elementKey) == null)
            //{
            //    redisclient.Set(elementKey, "defaultValue");
            //}
            //else {
            //    redisclient.Set(elementKey, "new default value");
            //}
            //Console.WriteLine("redise:value:"+redisclient.Get<string>(elementKey));
            Console.WriteLine(redisclient.Info);
        }
Пример #10
0
        private void button12_Click(object sender, EventArgs e)
        {
            client.AddItemToList("list:name", "p5");

            client.AddRangeToList("list:name", new List<string> { "p6", "p7" });
        }
Пример #11
0
        //临时使用
        private void NewMethod_test()
        {
            string curenttime = DateTime.Now.ToString();

            if (DateTime.Parse(curenttime).Hour >= 8)
            {
                //curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
            }
            else if (DateTime.Parse(curenttime).Hour >= 8)
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 10:09:00");
            }
            else
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 08:00:00");
            }

            this.richTextBox1.Invoke(new ThreadStart(delegate()
            {
                richTextBox1.Text           = "【卖家网】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                richTextBox1.SelectionStart = richTextBox1.TextLength;
                richTextBox1.ScrollToCaret();
            }));
            writeR(this.richTextBox1, "【卖家网】下次时间:" + curenttime + "...");

            while (true)
            {
                if (DateTime.Now >= DateTime.Parse(curenttime))
                {
                    try
                    {
                        this.richTextBox1.Invoke(new ThreadStart(delegate()
                        {
                            if (this.richTextBox1.Lines.Length > 40)
                            {
                                richTextBox1.Clear();
                            }
                            richTextBox1.Text           = "【卖家网】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                            richTextBox1.SelectionStart = richTextBox1.TextLength;
                            richTextBox1.ScrollToCaret();
                        }));
                        writeR(this.richTextBox1, "开始查询URL...");
                        string sqlStr = "select  '{\"category\": \"'+category+'\",\"url\": \"'+url+'\"}' from  dba.dbo.卖家网采集页面信息定时推送 ";
                        //sqlStr = "select  '{\"category\": \"'+category+'\",\"url\": \"'+url+'\"}' from  dba.dbo.卖家网采集页面信息定时推送 where category='净水器'";
                        sqlStr = "select  '{\"category\": \"'+category+'\",\"url\": \"'+url+'\"}' from  dba.dbo.卖家网采集页面信息定时推送 where category='投影仪'";
                        //sqlStr = "select  '{\"category\": \"'+category+'\",\"url\": \"'+url+'\"}' from  dba.dbo.卖家网采集页面信息定时推送 where category='电烤箱'";
                        //sqlStr = "select  '{\"category\": \"'+category+'\",\"url\": \"'+url+'\"}' from  dba.dbo.卖家网采集页面信息定时推送 where category='微波炉'";
                        sqlStr = " select top 100  '{\"url\": \"'+Urls+'\",\"attr\":{\"urlleibie\": \"'+Urlleibie+'\",\"urlweb\": \"'+(case when urlweb='tm' then'天猫商城' when urlweb='jd' then '京东商城' when urlweb='sn' then '苏宁易购' when urlweb='yhd' then '1号电' when urlweb='dd' then '当当网' when urlweb='gm' then '国美在线' when urlweb='ymx' then '亚马逊' when urlweb='tb' then '淘宝网' else urlweb end)+'\",\"brand\": \"'+ISNULL(spbjpinpai,'')+'\",\"model\": \"'+ISNULL(spbjjixing,'')+'\"}}' from  URLDATA_TM where NEED=1  AND URLLEIBIE='智能手机'";
                        DataTable dt = db.selectDatas(sqlStr);

                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        writeR(this.richTextBox1, "URL插入redis 共有:" + urlList.Count + "...");
                        //RedisClient client = new RedisClient("192.168.2.245", 6379);
                        //RedisClient client = new RedisClient("117.122.192.50", 6479);
                        RedisClient client = new RedisClient("117.23.4.139", 15480);
                        client.AddRangeToList("dpc_maijiawang:url_list", urlList);
                        //client.AddRangeToList("SqlServerInsertAllUrl:start_urls_info", urlList);
                        //client.AddRangeToList("comment_spider:start_urls_info", urlList);
                        writeR(this.richTextBox1, "成功,等待下次...");

                        if (DateTime.Parse(curenttime).Hour >= 16)
                        {
                            curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
                        }
                        else if (DateTime.Parse(curenttime).Hour >= 8)
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:00:00");
                        }
                        else
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 08:00:00");
                        }
                        writeR(this.richTextBox1, "【卖家网】下次时间:" + curenttime + "...");
                    }
                    catch (Exception ecppp)
                    {
                        writeR(this.richTextBox1, "报错:" + ecppp.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(1000 * 60 * 10);
                }
            }
        }
Пример #12
0
        // 改成一次:每天6点
        private void sixDailyNewMethod()
        {
            string curenttime = DateTime.Now.ToString();

            if (DateTime.Parse(curenttime).Hour >= 6)
            {
                curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 6:00:00");
            }
            else if (DateTime.Parse(curenttime).Hour > 16)
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 23:00:00");
            }
            else if (DateTime.Parse(curenttime).Hour > 8)
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:00:00");
            }
            else
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 8:00:00");
            }

            this.richTextBox2.Invoke(new ThreadStart(delegate()
            {
                richTextBox2.Text           = "【日报】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                richTextBox2.SelectionStart = richTextBox2.TextLength;
                richTextBox2.ScrollToCaret();
            }));
            writeR(this.richTextBox2, "【日报】下次时间:" + curenttime + "...");

            while (true)
            {
                if (DateTime.Now >= DateTime.Parse(curenttime))
                {
                    try
                    {
                        this.richTextBox2.Invoke(new ThreadStart(delegate()
                        {
                            if (this.richTextBox2.Lines.Length > 40)
                            {
                                richTextBox2.Clear();
                            }
                            richTextBox2.Text           = "【日报】采集......请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                            richTextBox2.SelectionStart = richTextBox2.TextLength;
                            richTextBox2.ScrollToCaret();
                        }));
                        writeR(this.richTextBox2, "开始查询URL...");

                        string    sqlStr = "select '{\"Urls\": \"'+Urls+'\",\"Urlleibie\": \"'+Urlleibie+'\",\"Urlweb\": \"'+Urlweb+'\",\"spbjpinpai\": \"'+ISNULL(spbjpinpai,'')+'\",\"spbjjixing\": \"'+ISNULL(spbjjixing,'')+'\",\"pc\":\"" + curenttime + "\"}' from(select * from URLDATA_TM where (spbjpinpai like '%海尔%' or spbjpinpai like '%西门子%' or spbjpinpai like '%美的%' or spbjpinpai like '%容声%' or spbjpinpai like '%美菱%' or spbjpinpai like '%康佳%' or spbjpinpai like '%奥马%' or spbjpinpai like '%TCL%' or spbjpinpai like '%三星%' or spbjpinpai like '%海信%' or spbjpinpai like '%韩电%' or spbjpinpai like '%创维%' or spbjpinpai like '%松下%' or spbjpinpai like '%新飞%' or spbjpinpai like '%博世%' or spbjpinpai like '%澳柯玛%' or spbjpinpai like '%格兰仕%' or spbjpinpai like '%晶弘%' or spbjpinpai like '%惠而浦%' or spbjpinpai like '%卡萨帝%' or spbjpinpai like '%统帅%') and Urlleibie='冰箱' union select * from URLDATA_TM where (spbjpinpai like '%小天鹅%' or spbjpinpai like '%海尔%' or spbjpinpai like '%西门子%' or spbjpinpai like '%美的%' or spbjpinpai like '%三洋帝度%' or spbjpinpai like '%格兰仕%' or spbjpinpai like '%TCL%' or spbjpinpai like '%松下%' or spbjpinpai like '%LG%' or spbjpinpai like '%三星%' or spbjpinpai like '%博世%' or spbjpinpai like '%大宇%' or spbjpinpai like '%海信%' or spbjpinpai like '%康佳%' or spbjpinpai like '%创维%' or spbjpinpai like '%荣事达%' or spbjpinpai like '%惠而浦%' or spbjpinpai like '%吉德%' or spbjpinpai like '%韩电%' or spbjpinpai like '%卡萨帝%' or spbjpinpai like '%统帅%') and Urlleibie='洗衣机' union select * from URLDATA_TM where (spbjpinpai like '%奥克斯%' or spbjpinpai like '%美的%' or spbjpinpai like '%格力%' or spbjpinpai like '%海尔%' or spbjpinpai like '%科龙%' or spbjpinpai like '%TCL%' or spbjpinpai like '%海信%' or spbjpinpai like '%志高%' or spbjpinpai like '%格兰仕%' or spbjpinpai like '%长虹%' or spbjpinpai like '%松下%' or spbjpinpai like '%统帅%' or spbjpinpai like '%富士通%' or spbjpinpai like '%三菱电机%' or spbjpinpai like '%扬子%' or spbjpinpai like '%美博%' or spbjpinpai like '%日立%' or spbjpinpai like '%万宝%' or spbjpinpai like '%泰瑞达%' or spbjpinpai like '%现代%') and Urlleibie='空调' union select * from URLDATA_TM where (spbjpinpai like '%创维%' or spbjpinpai like '%海信%' or spbjpinpai like '%TCL%' or spbjpinpai like '%长虹%' or spbjpinpai like '%康佳%' or spbjpinpai like '%海尔%' or spbjpinpai like '%三星%' or spbjpinpai like '%LG%' or spbjpinpai like '%索尼%' or spbjpinpai like '%夏普%' or spbjpinpai like '%乐视%' or spbjpinpai like '%小米%' or spbjpinpai like '%微鲸%' or spbjpinpai like '%酷开%' or spbjpinpai like '%KKTV%' or spbjpinpai like '%PPTV%' or spbjpinpai like '%mooka%' or spbjpinpai like '%看尚%' or spbjpinpai like '%暴风%' or spbjpinpai like '%风行%' or spbjpinpai like '%17TV%') and Urlleibie='彩电') A";
                        DataTable dt     = db.selectDatas(sqlStr);

                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        writeR(this.richTextBox2, "URL插入redis 共有:" + urlList.Count + "...");
                        RedisClient client = new RedisClient("117.122.192.50", 6479);
                        //client.LPush("proxytest:start_urls", Encoding.UTF8.GetBytes("11111111111111111111111111111111111"));
                        client.AddRangeToList("DailySellCountSpider:start_urls", urlList);

                        writeR(this.richTextBox2, "成功,等待下次...");
                        if (DateTime.Parse(curenttime).Hour >= 23)
                        {
                            curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
                        }
                        else if (DateTime.Parse(curenttime).Hour >= 16)
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 23:00:00");
                        }
                        else if (DateTime.Parse(curenttime).Hour >= 8)
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:00:00");
                        }
                        else
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 8:00:00");
                        }
                        writeR(this.richTextBox2, "【日报】下次时间:" + curenttime + "...");
                    }
                    catch (Exception ecppp)
                    {
                        writeR(this.richTextBox2, "报错:" + ecppp.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(1000 * 60 * 10);
                }
            }
        }
Пример #13
0
            public override void AddAllRecords()
            {
                var result = Records.Select(x => x.ToString()).ToList();

                RedisClient.AddRangeToList("1", result);
            }
Пример #14
0
        //临时使用
        private void NewMethod_test()
        {
            string curenttime = DateTime.Now.ToString();

            if (DateTime.Parse(curenttime).Hour >= 8)
            {
                //curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
            }
            else if (DateTime.Parse(curenttime).Hour >= 8)
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 10:09:00");
            }
            else
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 08:00:00");
            }

            this.richTextBox1.Invoke(new ThreadStart(delegate()
            {
                richTextBox1.Text           = "【周报】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                richTextBox1.SelectionStart = richTextBox1.TextLength;
                richTextBox1.ScrollToCaret();
            }));
            writeR(this.richTextBox1, "【周报】下次时间:" + curenttime + "...");

            while (true)
            {
                if (DateTime.Now >= DateTime.Parse(curenttime))
                {
                    try
                    {
                        this.richTextBox1.Invoke(new ThreadStart(delegate()
                        {
                            if (this.richTextBox1.Lines.Length > 40)
                            {
                                richTextBox1.Clear();
                            }
                            richTextBox1.Text           = "【周报】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                            richTextBox1.SelectionStart = richTextBox1.TextLength;
                            richTextBox1.ScrollToCaret();
                        }));
                        writeR(this.richTextBox1, "开始查询URL...");
                        string sqlStr = "select top 10000 '{\"Urls\": \"'+REPLACE(Urls,';',';')+'\",\"Urlleibie\": \"'+Urlleibie+'\",\"Urlweb\": \"'+Urlweb+'\",\"spbjpinpai\": \"'+ISNULL(spbjpinpai,'')+'\",\"spbjjixing\": \"'+ISNULL(spbjjixing,'')+'\",\"pc\":\"" + curenttime + "\"}' from urldata_tm where need=1 ";
                        //sqlStr = "select '{\"Urls\": \"'+REPLACE(Urls,';',';')+'\",\"Urlleibie\": \"'+Urlleibie+'\",\"Urlweb\": \"'+Urlweb+'\",\"spbjpinpai\": \"'+ISNULL(spbjpinpai,'')+'\",\"spbjjixing\": \"'+ISNULL(spbjjixing,'')+'\",\"pc\":\"" + curenttime + "\"}' from urldata_tm where need=1 and urlleibie in('智能手机','净化器','净水器','彩电','空调','冰箱','冰柜','洗衣机','厨电套餐','油烟机','燃气灶','消毒柜','热水器','微波炉','电烤箱','电蒸箱','洗碗机')";
                        //sqlStr = "select '{\"Urls\": \"'+REPLACE(Urls,';',';')+'\",\"Urlleibie\": \"'+Urlleibie+'\",\"Urlweb\": \"'+Urlweb+'\",\"spbjpinpai\": \"'+ISNULL(spbjpinpai,'')+'\",\"spbjjixing\": \"'+ISNULL(spbjjixing,'')+'\",\"pc\":\"" + curenttime + "\"}' from urldata_tm where need=1 and urlleibie not in('智能手机','净化器','净水器','彩电','空调','冰箱','冰柜','洗衣机','厨电套餐','油烟机','燃气灶','消毒柜','热水器','微波炉','电烤箱','电蒸箱','洗碗机')";
                        //sqlStr = "select '{\"Urls\": \"'+REPLACE(Urls,';',';')+'\",\"Urlleibie\": \"'+Urlleibie+'\",\"Urlweb\": \"'+Urlweb+'\",\"spbjpinpai\": \"'+ISNULL(spbjpinpai,'')+'\",\"spbjjixing\": \"'+ISNULL(spbjjixing,'')+'\",\"pc\":\"" + curenttime + "\"}' from urldata_tm where convert(nvarchar(10),writetime,120)>='2017-03-15' and need=1 and urlleibie in('电风扇','净化器','净水器','彩电','空调','冰箱','冰柜','洗衣机','厨电套餐','油烟机','燃气灶','消毒柜','热水器','微波炉','电烤箱','电蒸箱','洗碗机')";
                        sqlStr = "select '{\"Urls\": \"'+REPLACE(页面信息,';',';')+'\",\"Urlleibie\": \"'+品类+'\",\"Urlweb\": \"'+电商+'\",\"spbjpinpai\": \"'+ISNULL(品牌,'')+'\",\"spbjjixing\": \"'+ISNULL(机型,'')+'\",\"pc\":\"" + curenttime + "\"}' from CHDATA..URLDATA where 电商='天猫商城' AND need=0 and 品类='彩电'";
                        //sqlStr = "SELECT '{\"url\": \"'+页面信息+'\",\"attr\": {\"urlleibie\": \"'+品类+'\",\"urlweb\": \"'+电商+'\",\"brand\": \"'+品牌+'\",\"model\": \"'+机型+'\"}}' FROM CHDATA..URLDATA WHERE NEED=0 AND 品类='彩电' AND 电商='苏宁易购'";
                        sqlStr = "SELECT '{\"url\": \"'+页面信息+'\",\"attr\": {\"urlleibie\": \"'+品类+'\",\"urlweb\": \"'+电商+'\",\"brand\": \"'+品牌+'\",\"model\": \"'+机型+'\"}}' FROM CHDATA..URLDATA WHERE NEED=0 AND 品类 in('彩电') AND (  电商='苏宁易购')";
                        //sqlStr = "SELECT '{\"url\": \"'+页面信息+'\",\"attr\": {\"urlleibie\": \"'+品类+'\",\"urlweb\": \"'+电商+'\",\"brand\": \"'+品牌+'\",\"model\": \"'+机型+'\"}}' FROM CHDATA..URLDATA WHERE NEED=0 AND 品类 in('智能马桶','新风系统') AND (电商='京东商城')";
                        //sqlStr = "SELECT '{\"url\": \"'+页面信息+'\",\"attr\": {\"urlleibie\": \"'+品类+'\",\"urlweb\": \"'+电商+'\",\"brand\": \"'+品牌+'\",\"model\": \"'+机型+'\"}}' FROM CHDATA..URLDATA WHERE NEED=0 AND 电商  not in('苏宁易购','国美在线','天猫商城')";
                        //sqlStr = "SELECT '{\"url\": \"'+A.页面信息+'\",\"attr\": {\"urlleibie\": \"'+A.品类+'\",\"urlweb\": \"'+A.电商+'\",\"brand\": \"\",\"model\": \"\"}}' FROM (SELECT 页面信息,电商,品类 FROM CHDATA..URLDATAJD WHERE (NEED=0 OR NEED IS NULL) AND ISNULL(品类,'')!='' and 品类='彩电' and 电商 in('京东商城','苏宁易购') " +
                        //    ")A LEFT JOIN (SELECT 页面信息,电商,品类 FROM CHDATA..URLDATA WHERE NEED=0 and 品类='彩电' and 电商 in('京东商城','苏宁易购'))B  " +
                        //   "ON  A.页面信息 = B.页面信息 WHERE B.页面信息 IS NULL";

                        //sqlStr = "SELECT '{\"url\": \"'+A.页面信息+'\",\"attr\": {\"urlleibie\": \"'+A.品类+'\",\"urlweb\": \"'+A.电商+'\",\"brand\": \"''\",\"model\": \"''\"}}' FROM (SELECT 页面信息,电商,品类 FROM CHDATA..URLDATAJD WHERE (NEED=0 OR NEED IS NULL) AND ISNULL(品类,'')!='' and 品类 in('智能马桶','新风系统') and 电商 in('京东商城') " +
                        //  ")A LEFT JOIN (SELECT 页面信息,电商,品类 FROM CHDATA..URLDATA WHERE NEED=0 and 品类  in('智能马桶','新风系统') and 电商 in('京东商城'))B  " +
                        //"ON  A.页面信息 = B.页面信息 WHERE B.页面信息 IS NULL";
                        sqlStr = "select '{\"Urls\": \"'+ax.页面信息+'\",\"Urlleibie\": \"'+品类+'\",\"Urlweb\": \"天猫商城\",\"spbjpinpai\": \"'+品牌+'\",\"spbjjixing\": \"'+机型+'\",\"pc\": \"\"}'  from (select * from ( select * from dpcdata..线上周度补码表 where 周度='18w12' and(电商='天猫商城') )a left join (select * from dpcdata.._bf_wghurl)b on spurl=页面信息 where spurl is null )ax";

                        DataTable     dt      = db.selectDatas(sqlStr);
                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        writeR(this.richTextBox1, "URL插入redis 共有:" + urlList.Count + "...");
                        //RedisClient client = new RedisClient("117.122.192.50", 6479);
                        RedisClient client = new RedisClient("117.23.4.139", 15480);
                        //client.LPush("proxytest:start_urls", Encoding.UTF8.GetBytes("11111111111111111111111111111111111"));
                        //client.AddRangeToList("sellCountSpider:start_urls", urlList);
                        client.AddRangeToList("comment_spider_test:start_urls_info", urlList);
                        //client.AddRangeToList("mjd_comments_spider:start_urls_info", urlList);
                        writeR(this.richTextBox1, "成功,等待下次...");

                        if (DateTime.Parse(curenttime).Hour >= 16)
                        {
                            curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
                        }
                        else if (DateTime.Parse(curenttime).Hour >= 8)
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:00:00");
                        }
                        else
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 08:00:00");
                        }
                        writeR(this.richTextBox1, "【周报】下次时间:" + curenttime + "...");
                    }
                    catch (Exception ecppp)
                    {
                        writeR(this.richTextBox1, "报错:" + ecppp.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(1000 * 60 * 10);
                }
            }
        }
Пример #15
0
        // wgh : 0:05、10:05、16:05、21:05 修改采集时间
        private void NewMethod()
        {
            string curenttime = DateTime.Now.ToString();

            if (DateTime.Parse(curenttime).Hour >= 13 && DateTime.Parse(curenttime).Minute >= 5)
            {
                curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 0:10:00");
            }
            //      //curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 0:05:00");
            else if (DateTime.Parse(curenttime).Hour >= 16 && DateTime.Parse(curenttime).Minute >= 5)
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 21:05:00");
            }
            else if (DateTime.Parse(curenttime).Hour >= 10 && DateTime.Parse(curenttime).Minute >= 5)
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:05:00");
            }
            else
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 10:05:00");
            }

            this.richTextBox1.Invoke(new ThreadStart(delegate()
            {
                richTextBox1.Text           = "【周报】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                richTextBox1.SelectionStart = richTextBox1.TextLength;
                richTextBox1.ScrollToCaret();
            }));
            writeR(this.richTextBox1, "【周报】下次时间:" + curenttime + "...");

            while (true)
            {
                if (DateTime.Now >= DateTime.Parse(curenttime))
                {
                    try
                    {
                        this.richTextBox1.Invoke(new ThreadStart(delegate()
                        {
                            if (this.richTextBox1.Lines.Length > 40)
                            {
                                richTextBox1.Clear();
                            }
                            richTextBox1.Text           = "【周报】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                            richTextBox1.SelectionStart = richTextBox1.TextLength;
                            richTextBox1.ScrollToCaret();
                        }));
                        writeR(this.richTextBox1, "开始查询URL...");
                        string    sqlStr = "select  '{\"Urls\": \"'+REPLACE(Urls,';',';')+'\",\"Urlleibie\": \"'+Urlleibie+'\",\"Urlweb\": \"'+Urlweb+'\",\"spbjpinpai\": \"'+ISNULL(spbjpinpai,'')+'\",\"spbjjixing\": \"'+ISNULL(spbjjixing,'')+'\",\"pc\":\"" + curenttime + "\"}' from urldata_tm where need=1";
                        DataTable dt     = db.selectDatas(sqlStr);

                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        writeR(this.richTextBox1, "URL插入redis 共有:" + urlList.Count + " 条");
                        RedisClient client = new RedisClient("117.122.192.50", 6479);
                        //RedisClient client = new RedisClient("192.168.2.245", 6379);
                        client.AddRangeToList("sellCountSpider:start_urls", urlList);
                        //client.AddRangeToList("DailySellCountSpider:start_urls", urlList);
                        writeR(this.richTextBox1, "成功,等待下次...");

                        if (DateTime.Parse(curenttime).Hour >= 13 && DateTime.Parse(curenttime).Minute >= 5)
                        {
                            //if (DateTime.Parse(curenttime).Hour >= 20 && DateTime.Parse(curenttime).Minute >= 5)
                            curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:10:00");
                        }
                        else if (DateTime.Parse(curenttime).Hour >= 16 && DateTime.Parse(curenttime).Minute >= 5)
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 21:05:00");
                        }
                        else if (DateTime.Parse(curenttime).Hour >= 10 && DateTime.Parse(curenttime).Minute >= 5)
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:05:00");
                        }
                        else
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 10:05:00");
                        }

                        writeR(this.richTextBox1, "【周报】下次时间:" + curenttime + "...");
                    }
                    catch (Exception ecppp)
                    {
                        writeR(this.richTextBox1, "报错:" + ecppp.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(1000);
                }

                this.label1.Invoke(new ThreadStart(delegate()
                {
                    label1.Text = "当前时间:" + DateTime.Now.ToString() + "";
                }));
            }
        }
Пример #16
0
 private void NewMethod()
 {
     while (true)
     {
         RedisClient client = new RedisClient("192.168.100.200", 6379);
         try
         {
             byte[] taskbyte = client.RPop("datatoredis:task");
             if (taskbyte != null)
             {
                 string taskinfo = System.Text.Encoding.UTF8.GetString(taskbyte);
                 if (taskinfo != "")
                 {
                     var    jo         = JObject.Parse(taskinfo);
                     string datatype   = Convert.ToString(jo["datatype"]);
                     string datasource = Convert.ToString(jo["datasource"]);
                     string redishost  = Convert.ToString(jo["redishost"]);
                     int    redisport  = Convert.ToInt32(jo["redisport"]);
                     string rediskey   = Convert.ToString(jo["rediskey"]);
                     string pattern    = Convert.ToString(jo["pattern"]);
                     string starttime  = Convert.ToString(jo["starttime"]);
                     int    nextaddmin = Convert.ToInt32(jo["nextaddmin"]);
                     if (datasource.ToLower() == "sql")
                     {
                         if (DateTime.Now >= Convert.ToDateTime(starttime))
                         {
                             if (nextaddmin > 0)
                             {
                                 starttime       = Convert.ToDateTime(starttime).AddMinutes(nextaddmin).ToString("yyyy-MM-dd HH:mm:ss");
                                 jo["starttime"] = starttime;
                                 taskinfo        = JsonConvert.SerializeObject(jo);
                                 client.LPush("datatoredis:task", Encoding.UTF8.GetBytes(taskinfo));
                                 writeR(this.richTextBox1, "LPush to [datatoredis:task] " + taskinfo);
                             }
                             DataTable dtResult = db.selectDatas(pattern);
                             writeR(this.richTextBox1, "Get pattern for result [" + pattern + "]");
                             writeR(this.richTextBox1, "Get result " + dtResult.Rows.Count);
                             List <string> urlList = new List <string>();
                             foreach (DataRow item in dtResult.Rows)
                             {
                                 urlList.Add(item[0].ToString());
                             }
                             RedisClient dataClient = new RedisClient(redishost, redisport);
                             dataClient.AddRangeToList(rediskey, urlList);
                             writeR(this.richTextBox1, "Souccess");
                             writeR(this.richTextBox1, "***************");
                             writeR(this.richTextBox1, "***************");
                         }
                         else
                         {
                             taskinfo = JsonConvert.SerializeObject(jo);
                             client.LPush("datatoredis:task", Encoding.UTF8.GetBytes(taskinfo));
                         }
                     }
                 }
             }
         }
         catch (Exception ecp)
         {
             writeR(this.richTextBox1, "[Error]" + ecp.Message);
         }
         Thread.Sleep(1000 * 60 * 5);
     }
 }
Пример #17
0
 /// <summary>
 /// 为key添加多个值,并设置过期时间
 /// </summary>
 public void Add(string key, List <string> values, DateTime dt)
 {
     RedisClient.AddRangeToList(key, values);
     RedisClient.ExpireEntryAt(key, dt);
 }
Пример #18
0
        //推送评论url.
        /// <summary>
        /// 推送评论url
        /// </summary>
        private void urlPingLun()
        {
            string curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:05:00");

            //curenttime = DateTime.Now.ToString("yyyy-MM-dd 10:14:00");
            richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":【周报评论】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......");
            richtextwriteR(this.richTextBox_plurl, "【周报评论】下次时间:" + curenttime + "...0000");
            while (true)
            {
                if (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") == curenttime)
                {
                    try
                    {
                        //查找需要周度推送的品类
                        string weekCategory = ReadXML("WeekCategory");//周度品类
                        richtextwriteR(this.richTextBox_plurl, "周度采集的品类:" + weekCategory + "");
                        if (weekCategory != "")
                        {
                            weekCategory = " AND 品类 NOT IN " + weekCategory + " ";
                        }
                        string monthCategory = ReadXML("MonthCategory");
                        richtextwriteR(this.richTextBox_plurl, "月度采集的品类:" + monthCategory + "");
                        if (monthCategory != "")
                        {
                            monthCategory = " AND 品类 NOT IN " + monthCategory + " ";
                        }

                        //推送所有url
                        string        strSql  = "SELECT '{\"url\": \"'+页面信息+'\",\"attr\": {\"urlleibie\": \"'+品类+'\",\"urlweb\": \"'+电商+'\",\"brand\": \"'+品牌+'\",\"model\": \"'+机型+'\"}}' FROM URLDATA WHERE NEED=0 " + weekCategory + monthCategory + " AND 电商!='天猫商城'";
                        DataTable     dt      = db.selectDatas(strSql);
                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":URL插入redis 共有:" + urlList.Count + "");

                        bool isredisclient = true;
                        while (isredisclient)
                        {
                            try
                            {
                                client.AddRangeToList(plRedisKey, urlList);
                                isredisclient = false;
                            }
                            catch (Exception er)
                            {
                                richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":url 注入redis 失败 :" + er.Message + "");
                                //等等两秒,重新连接
                                Thread.Sleep(2000);
                                OpenRedisServer();
                            }
                        }

                        //开始推送一次天猫品类url
                        string tmCategory = ReadXML("TMCategory");

                        # region 天猫评论url,部分品类 url

                        if (tmCategory != "")//如果为空,则天猫url 不再采集评论
                        {
                            tmCategory = " AND 品类 IN " + tmCategory + "";

                            dt      = new DataTable();
                            urlList = new List <string>();
                            strSql  = "SELECT '{\"url\": \"'+页面信息+'\",\"attr\": {\"urlleibie\": \"'+品类+'\",\"urlweb\": \"'+电商+'\",\"brand\": \"'+品牌+'\",\"model\": \"'+机型+'\"}}' FROM URLDATA WHERE NEED=0 " + tmCategory + " AND 电商='天猫商城'";
                            dt      = db.selectDatas(strSql);
                            foreach (DataRow item in dt.Rows)
                            {
                                urlList.Add(item[0].ToString());
                            }

                            //client.AddRangeToList(plRedisKey, urlList);
                            isredisclient = true;
                            while (isredisclient)
                            {
                                try
                                {
                                    client.AddRangeToList(plRedisKey, urlList);
                                    isredisclient = false;
                                }
                                catch (Exception er)
                                {
                                    richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":url 注入redis 失败 :" + er.Message + "");
                                    //等等两秒,重新连接
                                    Thread.Sleep(2000);
                                    OpenRedisServer();
                                }
                            }
                            richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":天猫URL插入redis 共有:" + urlList.Count + "");
                        }

                        #endregion

                        dt      = new DataTable();
                        urlList = new List <string>();
                        strSql  = "SELECT '{\"url\": \"'+A.页面信息+'\",\"attr\": {\"urlleibie\": \"'+A.品类+'\",\"urlweb\": \"'+A.电商+'\",\"brand\": \"\",\"model\": \"\"}}' FROM (SELECT 页面信息,电商,品类 FROM URLDATAJD WHERE (NEED=0 OR NEED IS NULL) AND ISNULL(品类,'')!='' AND 电商!='天猫商城' " + weekCategory + monthCategory + " " +
                                  ")A LEFT JOIN (SELECT 页面信息,电商,品类 FROM URLDATA WHERE NEED=0 AND 电商!='天猫商城' " + weekCategory + monthCategory + ")B " +
                                  "ON  A.页面信息 = B.页面信息 WHERE B.页面信息 IS NULL";
                        dt = db.selectDatas(strSql);
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        //client.AddRangeToList(plRedisKey, urlList);
                        isredisclient = true;
                        while (isredisclient)
                        {
                            try
                            {
                                client.AddRangeToList(plRedisKey, urlList);
                                isredisclient = false;
                            }
                            catch (Exception er)
                            {
                                richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":url 注入redis 失败 :" + er.Message + "");
                                //等等两秒,重新连接
                                Thread.Sleep(2000);
                                OpenRedisServer();
                            }
                        }

                        richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":查询临时url结束, 共: " + urlList.Count + "");

                        if (weekCategory != "")
                        {
                            #region  //周一 凌晨开始采集的url(不包含天猫url)

                            if (DateTime.Now.DayOfWeek.ToString() == "Monday")
                            {
                                dt      = new DataTable();
                                urlList = new List <string>();
                                strSql  = "SELECT '{\"url\": \"'+页面信息+'\",\"attr\": {\"urlleibie\": \"'+品类+'\",\"urlweb\": \"'+电商+'\",\"brand\": \"'+品牌+'\",\"model\": \"'+机型+'\"}}' FROM URLDATA WHERE NEED=0 " + weekCategory.ToUpper().ToString().Replace("NOT", "") + " AND 电商!='天猫商城'";
                                dt      = db.selectDatas(strSql);
                                foreach (DataRow item in dt.Rows)
                                {
                                    urlList.Add(item[0].ToString());
                                }
                                isredisclient = true;
                                while (isredisclient)
                                {
                                    try
                                    {
                                        client.AddRangeToList(plRedisKey, urlList);
                                        isredisclient = false;
                                    }
                                    catch (Exception er)
                                    {
                                        richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":url 注入redis 失败 :" + er.Message + "");
                                        //等等两秒,重新连接
                                        Thread.Sleep(2000);
                                        OpenRedisServer();
                                    }
                                }
                                //client.AddRangeToList(plRedisKey, urlList);

                                dt      = new DataTable();
                                urlList = new List <string>();
                                strSql  = "SELECT '{\"url\": \"'+A.页面信息+'\",\"attr\": {\"urlleibie\": \"'+A.品类+'\",\"urlweb\": \"'+A.电商+'\",\"brand\": \"\",\"model\": \"\"}}' FROM (SELECT 页面信息,电商,品类 FROM URLDATAJD WHERE (NEED=0 OR NEED IS NULL) AND ISNULL(品类,'')!='' AND 电商!='天猫商城' " + weekCategory.ToUpper().ToString().Replace("NOT", "") + " " +
                                          ")A LEFT JOIN (SELECT 页面信息,电商,品类 FROM URLDATA WHERE NEED=0 AND 电商!='天猫商城' " + weekCategory.ToUpper().ToString().Replace("NOT", "") + ")B " +
                                          "ON  A.页面信息 = B.页面信息 WHERE B.页面信息 IS NULL";
                                dt = db.selectDatas(strSql);
                                foreach (DataRow item in dt.Rows)
                                {
                                    urlList.Add(item[0].ToString());
                                }
                                isredisclient = true;
                                while (isredisclient)
                                {
                                    try
                                    {
                                        client.AddRangeToList(plRedisKey, urlList);
                                        isredisclient = false;
                                    }
                                    catch (Exception er)
                                    {
                                        richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":url 注入redis 失败 :" + er.Message + "");
                                        //等等两秒,重新连接
                                        Thread.Sleep(2000);
                                        OpenRedisServer();
                                    }
                                }
                                //client.AddRangeToList(plRedisKey, urlList);

                                richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":周度品类查询临时url结束, 共: " + urlList.Count + "");
                            }

                            #endregion
                        }
                        richtextwriteR(this.richTextBox_plurl, DateTime.Now.ToString() + ":over");
                        curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:05:00");
                        richtextwriteR(this.richTextBox_plurl, "【周报评论】下次时间:" + curenttime + "...");
                    }
Пример #19
0
 /// <summary>
 /// 为key添加多个值,并设置过期时间
 /// </summary>
 public void Add(string key, List <string> values, TimeSpan sp)
 {
     RedisClient.AddRangeToList(key, values);
     RedisClient.ExpireEntryIn(key, sp);
 }
Пример #20
0
 /// <summary>
 /// 为key添加多个值
 /// </summary>
 public void Add(string key, List <string> values)
 {
     RedisClient.AddRangeToList(key, values);
 }
Пример #21
0
 public void AddRangeToList(string listId, List <string> values)
 {
     redisClient.AddRangeToList(listId, values);
 }
Пример #22
0
        //每天9点
        private void NewMethod()
        {
            string curenttime = DateTime.Now.ToString();

            if (DateTime.Parse(curenttime).Hour >= 9 && DateTime.Parse(curenttime).Minute >= 5)
            {
                curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 09:00:00");
            }

            this.richTextBox1.Invoke(new ThreadStart(delegate()
            {
                richTextBox1.Text           = "【卖家网】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                richTextBox1.SelectionStart = richTextBox1.TextLength;
                richTextBox1.ScrollToCaret();
            }));
            writeR(this.richTextBox1, "【卖家网】下次时间:" + curenttime + "...");

            while (true)
            {
                if (DateTime.Now >= DateTime.Parse(curenttime))
                {
                    try
                    {
                        this.richTextBox1.Invoke(new ThreadStart(delegate()
                        {
                            if (this.richTextBox1.Lines.Length > 40)
                            {
                                richTextBox1.Clear();
                            }
                            richTextBox1.Text           = "【卖家网】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                            richTextBox1.SelectionStart = richTextBox1.TextLength;
                            richTextBox1.ScrollToCaret();
                        }));
                        writeR(this.richTextBox1, "开始查询URL...");
                        string    sqlStr = "select '{\"category\": \"'+category+'\",\"url\": \"'+url+'\"}' from  dba.dbo.卖家网采集页面信息定时推送";
                        DataTable dt     = db.selectDatas(sqlStr);

                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        writeR(this.richTextBox1, "URL插入redis 共有:" + urlList.Count + " 条");
                        RedisClient client = new RedisClient("192.168.2.245", 6379);
                        client.AddRangeToList("dpc_maijiawang:url_list", urlList);
                        writeR(this.richTextBox1, "成功,等待下次...");

                        if (DateTime.Parse(curenttime).Hour >= 9 && DateTime.Parse(curenttime).Minute >= 5)
                        {
                            curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 09:00:00");
                        }

                        writeR(this.richTextBox1, "【卖家网】下次时间:" + curenttime + "...");
                    }
                    catch (Exception ecppp)
                    {
                        writeR(this.richTextBox1, "报错:" + ecppp.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(1000);
                }

                this.label1.Invoke(new ThreadStart(delegate()
                {
                    label1.Text = "当前时间:" + DateTime.Now.ToString() + "";
                }));
            }
        }
Пример #23
0
 /// <summary>
 /// 向列表底部(右侧)批量添加数据
 /// </summary>
 /// <param name="list"></param>
 /// <param name="values"></param>
 public static void GetRangeToList(string list, List <string> values)
 {
     redisClient.AddRangeToList(list, values);
 }
Пример #24
0
        //0        8         16
        // wgh : 0:05、10:05、16:05、21:05 修改采集时间
        private void NewMethod_old()
        {
            string curenttime = DateTime.Now.ToString();

            if (DateTime.Parse(curenttime).Hour >= 16)
            {
                curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
            }
            else if (DateTime.Parse(curenttime).Hour >= 8)
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:00:00");
            }
            else
            {
                curenttime = DateTime.Now.ToString("yyyy-MM-dd 08:00:00");
            }

            this.richTextBox1.Invoke(new ThreadStart(delegate()
            {
                richTextBox1.Text           = "【周报】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                richTextBox1.SelectionStart = richTextBox1.TextLength;
                richTextBox1.ScrollToCaret();
            }));
            writeR(this.richTextBox1, "【周报】下次时间:" + curenttime + "...");

            while (true)
            {
                if (DateTime.Now >= DateTime.Parse(curenttime))
                {
                    try
                    {
                        this.richTextBox1.Invoke(new ThreadStart(delegate()
                        {
                            if (this.richTextBox1.Lines.Length > 40)
                            {
                                richTextBox1.Clear();
                            }
                            richTextBox1.Text           = "【周报】采集......\r\n请不要关闭程序......\r\n如有意外,请联系采集人员......\r\n";
                            richTextBox1.SelectionStart = richTextBox1.TextLength;
                            richTextBox1.ScrollToCaret();
                        }));
                        writeR(this.richTextBox1, "开始查询URL...");
                        string    sqlStr = "select '{\"Urls\": \"'+Urls+'\",\"Urlleibie\": \"'+Urlleibie+'\",\"Urlweb\": \"'+Urlweb+'\",\"spbjpinpai\": \"'+ISNULL(spbjpinpai,'')+'\",\"spbjjixing\": \"'+ISNULL(spbjjixing,'')+'\",\"pc\":\"" + curenttime + "\"}' from urldata_tm where need=1";
                        DataTable dt     = db.selectDatas(sqlStr);

                        List <string> urlList = new List <string>();
                        foreach (DataRow item in dt.Rows)
                        {
                            urlList.Add(item[0].ToString());
                        }
                        writeR(this.richTextBox1, "URL插入redis 共有:" + urlList.Count + "...");
                        RedisClient client = new RedisClient("117.122.192.50", 6479);
                        //client.LPush("proxytest:start_urls", Encoding.UTF8.GetBytes("11111111111111111111111111111111111"));
                        client.AddRangeToList("sellCountSpider:start_urls", urlList);
                        writeR(this.richTextBox1, "成功,等待下次...");

                        if (DateTime.Parse(curenttime).Hour >= 16)
                        {
                            curenttime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
                        }
                        else if (DateTime.Parse(curenttime).Hour >= 8)
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 16:00:00");
                        }
                        else
                        {
                            curenttime = DateTime.Now.ToString("yyyy-MM-dd 08:00:00");
                        }
                        writeR(this.richTextBox1, "【周报】下次时间:" + curenttime + "...");
                    }
                    catch (Exception ecppp)
                    {
                        writeR(this.richTextBox1, "报错:" + ecppp.ToString());
                    }
                }
                else
                {
                    Thread.Sleep(1000 * 60 * 10);
                }
            }
        }
Пример #25
0
        static void Main(string[] args)
        {
            using (IRedisClient client = new RedisClient("127.0.0.1", 6379, null, 0))
            {
                //删除当前数据库中的所有Key
                client.FlushDb();
                string hashId = "stu";
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("name", "Micahel Shen");
                dic.Add("age", "18");
                dic.Add("address", "anyue");
                #region 添加、获取字符串
                //新增Key,默认是做了序列化存储
                client.Set <string>("name", "clay");
                //读取key 一般不建议这个方法
                var value0 = client.GetValue("name");
                Console.WriteLine(JsonConvert.DeserializeObject <string>(value0));
                //读取二 推荐试用,帮我们作了反序列
                var value1 = client.Get <string>("name");
                Console.WriteLine(value1);
                Dictionary <string, string> disc = new Dictionary <string, string>();
                disc.Add("id", "001");
                disc.Add("name", "michaelshen");
                disc.Add("address", "anyuexian");
                #endregion
                #region 批量的写
                //批量的写
                client.SetAll(disc);

                var list = client.GetAll <string>(new string[] { "id", "name" });
                foreach (var item in list)
                {
                    Console.WriteLine(item);
                }
                #endregion
                #region 设置过期时间
                client.FlushDb();
                client.Set <string>("name", "Michael Shen", TimeSpan.FromSeconds(10));
                client.Set <string>("key", "Shen", DateTime.Now.AddSeconds(10));
                //如果读不到key则返回一个"";
                #endregion
                #region 追加字符串
                client.FlushDb();
                //client.Set("name", "Michael Shen");
                client.AppendToValue("name", "Michael Shen");
                client.AppendToValue("name", " is SPY");
                Console.WriteLine(client.Get <string>("name"));
                #endregion
                #region 自增自减
                client.FlushDb();
                var a = client.Increment("count", 1);
                client.Increment("count", 100);
                //自减
                client.Decrement("count", 1);
                var b = client.Decrement("count", 5);
                Console.WriteLine(client.Get <int>("count"));
                #endregion
                #region Add和Set
                //Add会先判断数据库中是否存在对应的key,如果存在,再Add的话,会失败,并返回false,否则成功并返回true
                client.FlushDb();
                Console.WriteLine(client.Add <string>("name", "michael Shen")); //true
                Console.WriteLine(client.Add <string>("name", "michael Shen")); //false
                Console.WriteLine(client.Add <string>("name", "Shen"));         //false
                //Set
                Console.WriteLine(client.Add <int>("age", 18));                 //true
                Console.WriteLine(client.Add <int>("age", 19));                 //true
                Console.WriteLine(client.Add <int>("age", 20));                 //true
                #endregion
                #region 判断Redis中是否包含某一个Key
                Console.WriteLine(client.ContainsKey("name"));  //true
                Console.WriteLine(client.ContainsKey("NoKey")); //true
                #endregion
                #region 获取类型
                client.FlushDb();
                client.Set <string>("name", "MichaelShen");
                var type = client.GetEntryType("name");
                Console.WriteLine(type);                         //String
                client.AddItemToList("list1", "asdga");
                Console.WriteLine(client.GetEntryType("list1")); //List
                #endregion
                #region Hash
                client.FlushDb();
                Console.WriteLine("Hash");
                client.SetEntryInHash(hashId, "name", "Michael Shen");
                client.SetEntryInHash(hashId, "age", "18");
                var value = client.GetValueFromHash(hashId, "name");
                Console.WriteLine(value);
                //批量操作
                Dictionary <string, string> stu1 = new Dictionary <string, string>();
                stu1.Add("name", "Michael Shen1");
                stu1.Add("Id", "2017060528");
                stu1.Add("age", "19");
                client.SetRangeInHash(hashId, stu1);
                var result = client.GetAllEntriesFromHash(hashId);
                foreach (var item in result)
                {
                    Console.WriteLine(item.Key + ":" + item.Value);
                }
                //如果hash集合中存在对应的key,则新增失败,否则新增成功
                var res  = client.SetEntryInHashIfNotExists(hashId, "Nkey", "new value"); //true
                var res1 = client.SetEntryInHashIfNotExists(hashId, "name", "new value"); //false
                Console.WriteLine(res);
                Console.WriteLine(res1);
                #endregion
                #region 存用户信息
                client.FlushDb();
                Console.Clear();
                //用String去存储用户信息对象
                //用户信息,首先把对象做一个json序列化,然后存储再Redis的string里,
                //但是如果需要修改这个对象中的其中一个属性值的时候,先把这个对象json字符串读取出来反序列化,
                //然后修改属性值,修改完后再继续序列化再存储进去


                //用hash存储用户信息对象
                client.StoreAsHash <User>(new User {
                    ID = "001", Age = "22", Name = "MichaelShen"
                });
                Console.WriteLine(client.GetFromHash <User>("001").ToString());
                #endregion
                #region Hash里面Key总数
                Console.Clear();
                client.FlushDb();
                client.SetRangeInHash(hashId, dic);
                Console.WriteLine(client.GetHashCount(hashId));
                #endregion
                #region 获取所有的Keys和Values
                Console.Clear();
                client.FlushDb();
                client.SetRangeInHash(hashId, dic);
                var keys   = client.GetHashKeys(hashId);
                var values = client.GetHashValues(hashId);
                foreach (var item in keys)
                {
                    Console.WriteLine(item);
                }
                foreach (var item in values)
                {
                    Console.WriteLine(item);
                }
                #endregion
                #region  除Hash里的key
                //接上
                Console.WriteLine(client.RemoveEntryFromHash(hashId, "age"));
                foreach (var item in client.GetHashKeys(hashId))
                {
                    Console.WriteLine(item);
                }
                client.SetEntryInHash(hashId, "age", "22");
                #endregion
                #region 判断Hash里是否包含某个Key项
                Console.Clear();
                Console.WriteLine(client.HashContainsEntry(hashId, "name"));
                Console.WriteLine(client.HashContainsEntry(hashId, "Nokey"));
                #endregion
                #region 给Hash里的数字自增
                client.SetEntryInHash(hashId, "count", "1");
                client.IncrementValueInHash(hashId, "count", 1);
                Console.WriteLine(client.GetValueFromHash(hashId, "count"));
                #endregion
                #region List
                client.FlushDb();
                Console.Clear();
                {
                    var libai = new User
                    {
                        ID   = "001",
                        Name = "李白",
                        Age  = "22"
                    };
                    var guanyu = new User
                    {
                        Age  = "23",
                        Name = "关于",
                        ID   = "002"
                    };
                    client.AddItemToList("list0", JsonConvert.SerializeObject(libai));
                    client.AddItemToList("list0", JsonConvert.SerializeObject(guanyu));
                    #region 从前面、后面插入
                    //从前面插入
                    client.PrependItemToList("list0", JsonConvert.SerializeObject(new User {
                        ID = "003", Age = "25", Name = "花木兰"
                    }));
                    //从后面插入
                    client.PushItemToList("list0", JsonConvert.SerializeObject(new User {
                        ID = "004", Age = "26", Name = "鲁班"
                    }));
                    #endregion
                    #region List设置过期时间
                    client.ExpireEntryAt("list0", DateTime.Now.AddSeconds(10));
                    #endregion
                    #region 批量操作
                    //批量增加
                    client.AddRangeToList("list1", new List <string> {
                        "fdasf", "sadfa", "fdsafsagdfs", "1354213"
                    });
                    var results = client.GetRangeFromList("list1", 0, 2);
                    foreach (var item in results)
                    {
                        Console.WriteLine(item);
                    }
                    #endregion
                    #region 当数据结构操作
                    //当栈来操作(后进先出)
                    client.AddItemToList("listNum", "1");
                    client.AddItemToList("listNum", "2");
                    client.AddItemToList("listNum", "3");
                    client.AddItemToList("listNum", "4");
                    //从尾部删除并返回对应的值
                    Console.WriteLine(client.RemoveEndFromList("listNum")); //4
                    Console.WriteLine(client.RemoveEndFromList("listNum")); //3
                    Console.WriteLine(client.RemoveEndFromList("listNum")); //2
                    Console.WriteLine(client.RemoveEndFromList("listNum")); //1
                    //当队列来操作(先进先出)
                    client.AddItemToList("listNum", "1");
                    client.AddItemToList("listNum", "2");
                    client.AddItemToList("listNum", "3");
                    client.AddItemToList("listNum", "4");
                    //从头部删除并返回对应的值
                    Console.WriteLine(client.RemoveStartFromList("listNum"));
                    Console.WriteLine(client.RemoveStartFromList("listNum"));
                    Console.WriteLine(client.RemoveStartFromList("listNum"));
                    Console.WriteLine(client.RemoveStartFromList("listNum"));

                    //Pop和Push(栈数据结构的操作-先进后出)
                    client.PushItemToList("listStack", "1");
                    client.PushItemToList("listStack", "2");
                    client.PushItemToList("listStack", "3");
                    client.PushItemToList("listStack", "4");
                    Console.WriteLine(client.PopItemFromList("listStack"));
                    Console.WriteLine(client.PopItemFromList("listStack"));
                    Console.WriteLine(client.PopItemFromList("listStack"));
                    Console.WriteLine(client.PopItemFromList("listStack"));
                    //从一个List中pop出来添加到另一个List的头部中
                    client.PushItemToList("fromList", "1");
                    client.PushItemToList("fromList", "2");
                    client.PushItemToList("fromList", "3");
                    client.PushItemToList("fromList", "4");
                    Console.WriteLine(client.PopAndPushItemBetweenLists("fromList", "toList"));
                    Console.WriteLine(client.PopAndPushItemBetweenLists("fromList", "toList"));
                    Console.WriteLine(client.PopAndPushItemBetweenLists("fromList", "toList"));
                    #endregion
                    #region 其他
                    //获取key的过期时间
                    Console.WriteLine(client.GetTimeToLive("fromList"));
                    client.ExpireEntryAt("fromList", DateTime.Now.AddSeconds(60));
                    Console.WriteLine(client.GetTimeToLive("fromList"));
                    #endregion
                }
                #endregion
            }
        }
Пример #26
0
 public void AddRangeToList(string key, List <string> list)
 {
     redisClient.AddRangeToList(key, list);
 }