示例#1
0
        public RES SortedSetTraverse(string dictName, string search, Func <string, string, double, int, int, bool> callback)
        {
            try
            {
                var resQuery = this.db.SortedSetScan(dictName, search, int.MaxValue);
                var count    = (int)resQuery.Count();

                var index = 0;
                foreach (var item in resQuery)
                {
                    if (null != callback)
                    {
                        var _continue = callback(dictName, item.Element.ToString(), item.Score, count, index++);
                        if (!_continue)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                return(RES.OK());
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
示例#2
0
 public RES SetTraverse(string dictName, string search, Func <string, string, int, int, bool> callback)
 {
     try
     {
         var count    = (int)(this.db.SetLength(dictName) % int.MaxValue);
         var resQuery = this.db.SetScan(dictName, search, count);
         var index    = 0;
         foreach (var item in resQuery)
         {
             if (null != callback)
             {
                 var _continue = callback(dictName, item, count, index++);
                 if (!_continue)
                 {
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#3
0
        /// <summary>
        /// 情感分析
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public RES SentimentAnalysis(string input)
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId  = secretId,
                    SecretKey = secretKey
                };

                ClientProfile clientProfile = new ClientProfile();
                HttpProfile   httpProfile   = new HttpProfile();
                httpProfile.Endpoint      = ("nlp.ap-shanghai.tencentcloudapi.com");
                clientProfile.HttpProfile = httpProfile;

                NlpClient client             = new NlpClient(cred, "ap-guangzhou", clientProfile);
                SentimentAnalysisRequest req = new SentimentAnalysisRequest();
                string strParams             = JSON.ToJson(new { Text = input });
                req = SentimentAnalysisRequest.FromJsonString <SentimentAnalysisRequest>(strParams);
                SentimentAnalysisResponse resp = client.SentimentAnalysis(req).
                                                 ConfigureAwait(false).GetAwaiter().GetResult();
                return(RES.OK(resp));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex.Message));
            }
        }
示例#4
0
        public RES CacheSet(string key, object val, TimeSpan?expiry = null)
        {
            try
            {
                var res = false;
                if (val is string)
                {
                    res = this.db.StringSet(key, val as string, expiry);
                }
                else if (val is int)
                {
                    res = this.db.StringSet(key, (int)val, expiry);
                }
                else if (val is long)
                {
                    res = this.db.StringSet(key, (long)val, expiry);
                }
                else if (val is object)
                {
                    res = this.db.StringSet(key, JSON.ToJson(val), expiry);
                }

                return(RES.OK(res));
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
示例#5
0
 public RES Dequeue <T>(string queueName)
 {
     try
     {
         if (!string.IsNullOrWhiteSpace(queueName))
         {
             var val = this.db.ListLeftPop(queueName);
             if (typeof(T) == typeof(string))
             {
                 return(RES.OK(val.ToString()));
             }
             else if (typeof(T).IsClass)
             {
                 var json = JSON.ToObject <T>(val);
                 return(RES.OK(json));
             }
             else
             {
                 return(RES.OK(val.Box()));
             }
         }
         return(RES.FAIL());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#6
0
 public RES RedisExecute(string connection, string command, object[] paramArr)
 {
     if (!string.IsNullOrWhiteSpace(connection))
     {
         return(RES.OK(REDIS.GetInst(0, connection).Execute(null, command, paramArr)));
     }
     else
     {
         return(RES.OK(REDIS.Current.Execute(null, command, paramArr)));
     }
 }
 public RES Stop()
 {
     try
     {
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL());
     }
 }
示例#8
0
 protected RES FinishCheckPoint <T>(T t) where T : Item, new()
 {
     try
     {
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#9
0
 protected RES SyncToDB <T>(T t) where T : Item, new()
 {
     try
     {
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#10
0
 public RES Execute(string serverId, string command, object[] paramArr)
 {
     try
     {
         var res = (RedisValue[])REDIS.redis.GetDatabase().Execute(command, paramArr);
         return(RES.OK(res.ToStringArray()));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#11
0
 public RES QueryKeys(string match, int db = 0)
 {
     try
     {
         var keys = server.Keys(db, match, int.MaxValue).Select(p => p.ToString()).ToList();
         return(RES.OK(keys));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#12
0
 public RES DictRemove(string dictName, string key)
 {
     try
     {
         var val = this.db.HashDelete(dictName, key);
         return((val) ? RES.OK(val) : RES.FAIL(val));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#13
0
 public RES KeyRemove(string key)
 {
     try
     {
         var val = this.db.KeyDelete(key);
         return((val) ? RES.OK(val) : RES.FAIL(val));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#14
0
 public RES RemoveListItem(string listName, string item, int count = 0)
 {
     try
     {
         var list     = new List <string>();
         var resCount = this.db.ListRemove(listName, item, count);
         return((0 < resCount) ? RES.OK(resCount) : RES.FAIL($"{listName}\t{resCount}\t{item}"));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#15
0
 public RES Remove <T>(T t) where T : Item, new()
 {
     try
     {
         this.RemoveFlat(t);
         this.RemoveFromList(t);
         this.RemoveSearchIndex(t);
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#16
0
 public RES Save <T>(T t) where T : Item, new()
 {
     try
     {
         ///记录要保存的数据
         this.SaveFlat(t);
         this.SaveToList(t);
         this.BuildSearchIndex(t);
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#17
0
        public RES DictAdd(string dictName, string key, object val)
        {
            try
            {
                if (val is string)
                {
                    this.db.HashSet(dictName, key, val as string);
                }
                else if (val.GetType() == typeof(DateTime))
                {
                    this.db.HashSet(dictName, key, val.ToString());
                }
                else if (val.GetType() == typeof(int))
                {
                    this.db.HashSet(dictName, key, (int)val);
                }
                else if (val.GetType() == typeof(long))
                {
                    this.db.HashSet(dictName, key, (long)val);
                }
                else if (val.GetType() == typeof(decimal))
                {
                    this.db.HashSet(dictName, key, Convert.ToDouble(val));
                }
                else if (val.GetType() == typeof(float))
                {
                    this.db.HashSet(dictName, key, (float)val);
                }
                else if (val.GetType() == typeof(double))
                {
                    this.db.HashSet(dictName, key, (double)val);
                }
                else if (val.GetType() == typeof(Guid))
                {
                    this.db.HashSet(dictName, key, val.ToString());
                }
                else if (val.GetType().IsClass)
                {
                    this.db.HashSet(dictName, key, JSON.ToJson(val));
                }

                return(RES.OK());
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
示例#18
0
 public RES DictGet(string dictName, string key)
 {
     try
     {
         var val = this.db.HashGet(dictName, key);
         if (val.IsNullOrEmpty)
         {
             return(RES.FAIL(null));
         }
         return(RES.OK(val.ToString()));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#19
0
 public RES Enqueue(string queueName, object val)
 {
     try
     {
         if (val is string)
         {
             this.db.ListRightPush(queueName, val as string);
         }
         else if (val.GetType() == typeof(DateTime))
         {
             this.db.ListRightPush(queueName, val.ToString());
         }
         else if (val.GetType() == typeof(int))
         {
             this.db.ListRightPush(queueName, (int)val);
         }
         else if (val.GetType() == typeof(long))
         {
             this.db.ListRightPush(queueName, (long)val);
         }
         else if (val.GetType() == typeof(decimal))
         {
             this.db.ListRightPush(queueName, (double)val);
         }
         else if (val.GetType() == typeof(float))
         {
             this.db.ListRightPush(queueName, (double)val);
         }
         else if (val.GetType() == typeof(double))
         {
             this.db.ListRightPush(queueName, (double)val);
         }
         else if (val.GetType() == typeof(Guid))
         {
             this.db.ListRightPush(queueName, val.ToString());
         }
         else if (val.GetType().IsClass)
         {
             this.db.ListRightPush(queueName, JSON.ToJson(val));
         }
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#20
0
 public RES SortedSetScan(string setName, string search, int pageSize)
 {
     try
     {
         var list = new List <string>();
         var res  = this.db.SortedSetScan(setName, search, pageSize).ToList();
         res.ForEach(p =>
         {
             list.Add(p.Element.ToString());
         });
         return(RES.OK(list));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#21
0
 public RES DictScan(string dictName, string search, int count)
 {
     try
     {
         var list = new List <string>();
         var res  = this.db.HashScan(dictName, search, count).ToList();
         res.ForEach(p =>
         {
             list.Add(p.Value.ToString());
         });
         return(RES.OK(list));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#22
0
 public RES SortedSetRemoveByScore(string setName, int start = int.MinValue, int stop = int.MaxValue)
 {
     try
     {
         var list = new List <string>();
         var res  = this.db.SortedSetRangeByScore(setName, start, stop).ToList();
         res.ForEach(p =>
         {
             list.Add(p.ToString());
         });
         return(RES.OK(list));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#23
0
 public RES GetListLastItems(string listName, int start = -20, int end = -1)
 {
     try
     {
         var list  = new List <string>();
         var items = this.db.ListRange(listName, start, end);
         items.ToList().ForEach(p =>
         {
             list.Add(p);
         });
         return((0 < list.Count) ? RES.OK(list) : RES.FAIL());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#24
0
 public RES KeyRemove(string[] keys)
 {
     try
     {
         var rKeys = new List <RedisKey>();
         keys.ToList().ForEach(p =>
         {
             rKeys.Add(p);
         });
         var val = this.db.KeyDelete(rKeys.ToArray());
         return((0 < val) ? RES.OK(val) : RES.FAIL(val));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#25
0
        public RES SetAdd(string setName, object val)
        {
            if (!this.server.IsConnected)
            {
                return(RES.FAIL($"Redis {nameof(this.server.IsConnected)} {this.server.IsConnected}"));
            }

            if (val is string)
            {
                this.db.SetAdd(setName, val as string);
            }
            else if (val.GetType() == typeof(DateTime))
            {
                this.db.SetAdd(setName, val.ToString());
            }
            else if (val.GetType() == typeof(int))
            {
                this.db.SetAdd(setName, (int)val);
            }
            else if (val.GetType() == typeof(long))
            {
                this.db.SetAdd(setName, (long)val);
            }
            else if (val.GetType() == typeof(decimal))
            {
                this.db.SetAdd(setName, (double)val);
            }
            else if (val.GetType() == typeof(float))
            {
                this.db.SetAdd(setName, (double)val);
            }
            else if (val.GetType() == typeof(double))
            {
                this.db.SetAdd(setName, (double)val);
            }
            else if (val.GetType() == typeof(Guid))
            {
                this.db.SetAdd(setName, val.ToString());
            }
            else if (val.GetType().IsClass)
            {
                this.db.SetAdd(setName, JSON.ToJson(val));
            }
            return(RES.OK());
        }
示例#26
0
 public RES SortedSetQuery(string setName, double start, double stop, bool isDesc, int pageIndex, int pageSize)
 {
     try
     {
         var list  = new List <string>();
         var order = isDesc ? Order.Descending : Order.Ascending;
         var res   = this.db.SortedSetRangeByScore(setName, start, stop, Exclude.None, order, (pageIndex * pageSize), pageSize).ToList();
         res.ForEach(p =>
         {
             list.Add(p.ToString());
         });
         return(RES.OK(list));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#27
0
 protected RES RemoveFromList <T>(T t) where T : Item, new()
 {
     try
     {
         const string prefix = "LIST";
         if (null != t)
         {
             var classFullName = $"{prefix}:{t.GetType().FullName.Replace(".", ":")}";
             REDIS.Current.DictRemove($"{classFullName}", t.ItemID.ToString());
             this.SaveDeleteNotice(t);
         }
         return(RES.OK());
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#28
0
 public RES SortedSetGetOnceByScore(string setName, int queryScore = 0, int tempScore = 0)
 {
     try
     {
         var list = new List <string>();
         var res  = this.db.SortedSetRangeByScore(setName, queryScore, queryScore, Exclude.None, Order.Descending, 0, 1).ToList();
         if (0 < res.Count)
         {
             var data = res.First().ToString();
             var res2 = this.db.SortedSetAdd(setName, data, tempScore);
             return(RES.OK(data));
         }
         return(RES.FAIL(res.Count));
     }
     catch (Exception ex)
     {
         return(RES.FAIL(ex));
     }
 }
示例#29
0
        protected RES SaveModifyNotice <T>(T t) where T : Item, new()
        {
            try
            {
                if (null == t || t.ItemID == Guid.Empty)
                {
                    return(RES.FAIL());
                }

                var key = $"MODIFY:{t.GetType().FullName.Replace(".", ":")}";
                REDIS.Current.Enqueue(key, new ChangeNotice {
                    ClassFullName = t.GetType().FullName, ItemID = t.ItemID, CreateTime = DateTime.Now.Ticks
                });

                return(RES.OK());
            }
            catch (Exception ex)
            {
                return(RES.FAIL(ex));
            }
        }
示例#30
0
 public RES SortedSetRemove(string setName, object val)
 {
     if (val is string)
     {
         this.db.SortedSetRemove(setName, val as string);
     }
     else if (val.GetType() == typeof(DateTime))
     {
         this.db.SortedSetRemove(setName, val.ToString());
     }
     else if (val.GetType() == typeof(int))
     {
         this.db.SortedSetRemove(setName, (int)val);
     }
     else if (val.GetType() == typeof(long))
     {
         this.db.SortedSetRemove(setName, (long)val);
     }
     else if (val.GetType() == typeof(decimal))
     {
         this.db.SortedSetRemove(setName, (double)val);
     }
     else if (val.GetType() == typeof(float))
     {
         this.db.SortedSetRemove(setName, (double)val);
     }
     else if (val.GetType() == typeof(double))
     {
         this.db.SortedSetRemove(setName, (double)val);
     }
     else if (val.GetType() == typeof(Guid))
     {
         this.db.SortedSetRemove(setName, val.ToString());
     }
     else if (val.GetType().IsClass)
     {
         this.db.SortedSetRemove(setName, JSON.ToJson(val));
     }
     return(RES.OK());
 }