Exemple #1
0
        public RedisRegistryProvider()
        {
            if (SeifApplication.AppEnv.GlobalConfiguration.RegistryConfiguration == null)
                throw new Exception("注册中心配置有误");

            string url = SeifApplication.AppEnv.GlobalConfiguration.RegistryConfiguration.Url;
            string collectionName = "RegistryData";

            var attrs = DictionaryUtils.GetFromConfig(SeifApplication.AppEnv.GlobalConfiguration.RegistryConfiguration.AddtionalFields);
            if (attrs != null && attrs.ContainsKey(AttrKeys.Registry_RedisCollectionName) )
            {
                if (!string.IsNullOrEmpty(attrs[AttrKeys.Registry_RedisCollectionName]))
                {
                    collectionName = attrs[AttrKeys.Registry_RedisCollectionName];
                }
            }

            _redisClient = new RedisClient(url);
            _typedClient = _redisClient.As<RegistryDataInfo>();
            _table = _typedClient.Lists[collectionName];

            _redisSubscription = _redisClient.CreateSubscription();
            _redisSubscription.OnMessage += (channel, msg) =>
            {
                var data = _serializer.Deserialize<ServiceRegistryMetta>(msg);
                if (this.ServiceChanged == null) return;

                this.ServiceChanged(this, new ServiceNotifyEventArgs
                {
                    Data = data
                });
            };
        }
Exemple #2
0
 public static void List_RemoveAll <T>(string key)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         var redisTypedClient = redis.As <T>();
         redisTypedClient.Lists[key].RemoveAll();
     }
 }
Exemple #3
0
 public static void List_Add <T>(string key, T t)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         var redisTypedClient = redis.As <T>();
         redisTypedClient.AddItemToList(redisTypedClient.Lists[key], t);
     }
 }
Exemple #4
0
 public static bool List_Remove <T>(string key, T t)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         var redisTypedClient = redis.As <T>();
         return(redisTypedClient.RemoveItemFromList(redisTypedClient.Lists[key], t) > 0);
     }
 }
Exemple #5
0
 public bool Set_Remove <T>(string key, T t)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         var redisTypedClient = redis.As <T>();
         return(redisTypedClient.Sets[key].Remove(t));
     }
 }
Exemple #6
0
 public void Set_Add <T>(string key, T t)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         var redisTypedClient = redis.As <T>();
         redisTypedClient.Sets[key].Add(t);
     }
 }
Exemple #7
0
 public void List_Insert <T>(string key, T t)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         var redisTypedClient = redis.As <T>();
         redisTypedClient.SetItemInList(redisTypedClient.Lists[key], 0, t);
     }
 }
Exemple #8
0
 public static List <T> List_GetList <T>(string key)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         redis.Password = Constant.RedisPwd;
         var c = redis.As <T>();
         return(c.Lists[key].GetRange(0, c.Lists[key].Count));
     }
 }
        private void btnReadAllItems_Click(object sender, EventArgs e)
        {
            using (IRedisClient client = getClient())
            {
                var personClient = client.As <Person>();

                dgvPerson.DataSource = personClient.GetAll();
            }
        }
Exemple #10
0
 /// <summary>
 /// 移除集合某个值
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="key">键值</param>
 /// <param name="t">数值</param>
 /// <param name="dbId">库</param>
 /// <returns></returns>
 public static bool Set_Remove <T>(string key, T t, long dbId = 0)
 {
     using (IRedisClient redis = CreateManager(dbId).GetClient())
     {
         redis.Password = connectPassword;
         var redisTypedClient = redis.As <T>();
         return(redisTypedClient.Sets[key].Remove(t));
     }
 }
Exemple #11
0
 /// <summary>
 /// 添加集合
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="key">键值</param>
 /// <param name="t">数值</param>
 /// <param name="dbId">库</param>
 public static void Set_Add <T>(string key, T t, long dbId = 0)
 {
     using (IRedisClient redis = CreateManager(dbId).GetClient())
     {
         redis.Password = connectPassword;
         var redisTypedClient = redis.As <T>();
         redisTypedClient.Sets[key].Add(t);
     }
 }
Exemple #12
0
 /// <summary>
 /// 获取列表所有数据
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="key">键值</param>
 /// <param name="dbId">库数据</param>
 /// <returns></returns>
 public static List <T> List_GetList <T>(string key, long dbId = 0)
 {
     using (IRedisClient redis = CreateManager(dbId).GetClient())
     {
         redis.Password = connectPassword;
         var c = redis.As <T>();
         return(c.Lists[key].GetRange(0, c.Lists[key].Count));
     }
 }
Exemple #13
0
 public static bool Set_Remove <T>(string key, T t)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         redis.Password = Constant.RedisPwd;
         var redisTypedClient = redis.As <T>();
         return(redisTypedClient.Sets[key].Remove(t));
     }
 }
Exemple #14
0
 /// <summary>
 /// 移除列表某个值
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="key">键值</param>
 /// <param name="t">值</param>
 /// <param name="dbId">库</param>
 /// <returns></returns>
 public static bool List_Remove <T>(string key, T t, long dbId = 0)
 {
     using (IRedisClient redis = CreateManager(dbId).GetClient())
     {
         redis.Password = connectPassword;
         var redisTypedClient = redis.As <T>();
         return(redisTypedClient.RemoveItemFromList(redisTypedClient.Lists[key], t) > 0);
     }
 }
Exemple #15
0
 public List <T> List_GetList <T>(string key)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         //var c = redis.GetTypedClient<T>();
         var c = redis.As <T>();
         return(c.Lists[key].GetRange(0, c.Lists[key].Count));
     }
 }
Exemple #16
0
 public static List <T> List_GetRange <T>(string key, int start, int count)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         redis.Password = Constant.RedisPwd;
         var c = redis.As <T>();
         return(c.Lists[key].GetRange(start, start + count - 1));
     }
 }
Exemple #17
0
 public List <T> List_GetRange <T>(string key, int start, int count)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         //var c = redis.GetTypedClient<T>();
         var c = redis.As <T>();
         return(c.Lists[key].GetRange(start, start + count - 1));
     }
 }
Exemple #18
0
 /// <summary>
 /// 移除列表所有值
 /// </summary>
 /// <typeparam name="T">类型</typeparam>
 /// <param name="key">键值</param>
 /// <param name="dbId">库Id</param>
 public static void List_RemoveAll <T>(string key, long dbId = 0)
 {
     using (IRedisClient redis = CreateManager(dbId).GetClient())
     {
         redis.Password = connectPassword;
         var redisTypedClient = redis.As <T>();
         redisTypedClient.Lists[key].RemoveAll();
     }
 }
Exemple #19
0
 public static void Set_Add <T>(string key, T t)
 {
     using (IRedisClient redis = prcm.GetClient())
     {
         redis.Password = Constant.RedisPwd;
         var redisTypedClient = redis.As <T>();
         redisTypedClient.Sets[key].Add(t);
     }
 }
 /// <summary>
 /// 依据HashId获取数据
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="hashId">HashId</param>
 /// <param name="dataKey">关键码值</param>
 /// <returns>IQueryable</returns>
 public IQueryable <T> GetAll <T>(string hashId, string dataKey)
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         var _filtered = redisClient.GetAllEntriesFromHash(hashId).Where(c => c.Value.Equals(dataKey, StringComparison.InvariantCultureIgnoreCase));
         var _ids      = _filtered.Select(c => c.Key);
         return(redisClient.As <T>().GetByIds(_ids).AsQueryable());
     }
 }
Exemple #21
0
        public RedisUnitOfWork(RedisDataContext context)
        {
            _disposedLists = false;
            _client        = context.Client();
            _typedClient   = _client.As <TEntity>();
            string type = typeof(TEntity).ToString();

            _storeKey  = RedisUtils.GetListKey(type, RedisOperation.Save);
            _removeKey = RedisUtils.GetListKey(type, RedisOperation.Delete);
        }
Exemple #22
0
        public List <VietlottvnAppearance> GetAllAppearance001()
        {
            //Create a 'strongly-typed' API that makes all Redis Value operations to apply against VietlottvnAppearance
            IRedisTypedClient <VietlottvnAppearance> lstAppearance = _redisClient.As <VietlottvnAppearance>();
            //Redis lists implement IList<T> while Redis sets implement ICollection<T>
            var lstApp = lstAppearance.Lists["urn:vietlottvnappearance"];
            List <VietlottvnAppearance> myList = lstApp.GetAll();

            return(myList);
        }
 public Task DequeueEventAsync(long id)
 {
     using (IRedisClient redis = clientsManager.GetClient())
     {
         var eventMessageClient = redis.As <ServerEventMessageEntity>();
         var entity             = eventMessageClient.GetById(id);
         eventMessageClient.Lists[NCORE_EVENT_LIST].Remove(entity);
     }
     return(Task.CompletedTask);
 }
Exemple #24
0
        public static void storeContext <T>(this DummyClass dummyObject, IRedisClient client, T ctx)
        {
            var typedClient = client.As <T>();

            typedClient.Store(ctx);
            var item = IOCTest.Container.GetInstance <IIOCTestItem>();

            IOCTest.Container.GetInstance <IIOCTestItem>();
            IOCTest.Container.GetInstance <IIOCTestItem>();
            Console.WriteLine("got item");
        }
        public SubMapBinder[] GetMapSubMapsBinder(int mapid)
        {
            AssertInitialized();

            using (IRedisClient client = m_clientManager.GetClient())
            {
                IRedisTypedClient <long[]> keysClient = client.As <long[]>();
                IRedisHash <int, long[]>   hash       = keysClient.GetHash <int>(REDIS_MAPS);

                if (!hash.ContainsKey(mapid))
                {
                    return(new SubMapBinder[0]);
                }

                long[] submaps      = hash[mapid];
                var    submapClient = (RedisTypedClient <SubMapBinder>)client.As <SubMapBinder>();

                return(submapClient.GetValuesFromHash(submapClient.GetHash <long>(REDIS_KEY), submaps).ToArray());
            }
        }
 /// <summary>
 /// 判断TypeName是否存在
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <returns>是否存在</returns>
 /// 时间:2016/8/4 15:38
 /// 备注:
 public bool Contains <T>()
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         using (IRedisTypedClient <T> typedclient = redisClient.As <T>())
         {
             return(typedclient.TypeIdsSet.Count > 0);
         }
     }
 }
 /// <summary>
 /// 设置集合缓存
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="listItems">泛型集合</param>
 public void SetAll <T>(IEnumerable <T> listItems)
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         using (IRedisTypedClient <T> typedclient = redisClient.As <T>())
         {
             typedclient.StoreAll(listItems);
         }
     }
 }
 /// <summary>
 /// 设置Hash类型缓存
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="item">缓存项</param>
 /// <param name="hashId">HashId</param>
 /// <param name="dataKey">关键码值</param>
 /// <param name="keyName">关键码值属性</param>
 public void Set <T>(T item, string hashId, string dataKey, string keyName)
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         Type         _type = item.GetType();
         PropertyInfo _prop = _type.GetProperty(keyName);
         redisClient.SetEntryInHash(hashId, _prop.GetValue(item, null).ToString(), dataKey.ToLower());
         redisClient.As <T>().Store(item);
     }
 }
 /// <summary>
 /// 设置缓存
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="item">缓存项</param>
 public void Set <T>(T item)
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         using (IRedisTypedClient <T> typedclient = redisClient.As <T>())
         {
             typedclient.Store(item);
         }
     }
 }
 /// <summary>
 /// 条件获取
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="keySelector">条件委托</param>
 /// <returns>集合</returns>
 public IEnumerable <T> GetAll <T>(Func <T, bool> keySelector)
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         using (IRedisTypedClient <T> typedclient = redisClient.As <T>())
         {
             return(typedclient.GetAll().Where(keySelector));
         }
     }
 }
 /// <summary>
 /// 获取所有
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <returns>集合</returns>
 public IList <T> GetAll <T>()
     where T : IHasId <string>
 {
     using (IRedisClient redisClient = PRM.GetClient())
     {
         using (IRedisTypedClient <T> typedclient = redisClient.As <T>())
         {
             return(typedclient.GetAll());
         }
     }
 }
 public RedisPostRepository(Uri serverUri)
 {
     _bareClient = new RedisClient(serverUri);
     _client = _bareClient.As<Post>();
 }
 public RedisPostRepository(string host, int port, string password = null)
 {
     _bareClient = new RedisClient(host, port, password);
     _client = _bareClient.As<Post>();
 }
 public RedisPostRepository()
 {
     _bareClient = new RedisClient();
     _client = _bareClient.As<Post>();
 }
 public RedisContainerCacheStrategy()
 {
     //_config = RedisConfigInfo.GetConfig();
     _client = RedisManager.GetClient();
     _cache = _client.As<IContainerItemCollection>();
 }