Example #1
0
        public void TestSet()
        {
            var client = cacheClient as RedisClient;
            IRedisTypedClient <UserInfoDto> typeClient = client.As <UserInfoDto>();

            typeClient.DeleteAll();
            IRedisSet <UserInfoDto> set = typeClient.Sets["TestSet"];
            var sortSet = typeClient.SortedSets["TestSet1"];

            var list = GetUsers();

            set.Clear();
            list.ForEach(x => set.Add(x));
            list.ForEach(x => sortSet.Add(x));

            Console.WriteLine("写入完成");
            Console.ReadLine();

            var item = sortSet.Where(t => t.StaffId == "StaffId_7").ToList();

            //var result =  set.GetAll();

            Console.WriteLine(item.ToString());
            Console.ReadLine();
        }
Example #2
0
 /// <summary>
 /// 实例化连接
 /// </summary>
 public DefaultRedisStore(IRedisBase _redisBase, IOptions <RedisOptions> options, IRedisSet _redisSet)
 {
     redisBase = _redisBase;
     //初始化key的前缀
     redisPrefixKey = options.Value.RedisPrefix ?? new RedisPrefixKey();
     redisSet       = _redisSet;
 }
        /// <summary>
        /// Gets all connections that match the filter
        /// </summary>
        /// <param name="filter">The filter to apply on the data set</param>
        /// <returns></returns>
        public Task <IEnumerable <T> > GetConnectionsAsync(Expression <Func <T, bool> > filter)
        {
            using IRedisClient redisClient = RedisManager.GetClient();
            IRedisTypedClient <T> redisTypedClient = redisClient.As <T>();
            IRedisSet <T>         items            = redisTypedClient.Sets[Key];

            return(Task.FromResult(filter != null ? items.AsQueryable().Where(filter).AsEnumerable() : items.AsEnumerable()));
        }
        /// <summary>
        /// Gets all connections
        /// </summary>
        /// <returns></returns>
        public Task <IEnumerable <T> > GetConnectionsAsync()
        {
            using IRedisClient redisClient = RedisManager.GetClient();
            IRedisTypedClient <T> redisTypedClient = redisClient.As <T>();
            IRedisSet <T>         items            = redisTypedClient.Sets[Key];

            return(Task.FromResult(items.AsEnumerable()));
        }
 public override void SetUp()
 {
     base.SetUp();
     this._redis = this.Redis.As <T>();
     this._set   = this._redis.Sets[_setId];
     this._set2  = this._redis.Sets[_setId2];
     this._set3  = this._redis.Sets[_setId3];
 }
        public List <T> GetSortedEntryValues(IRedisSet <T> fromSet, int startingFrom, int endingAt)
        {
            var sortOptions = new SortOptions {
                Skip = startingFrom, Take = endingAt,
            };
            var multiDataList = client.Sort(fromSet.Id, sortOptions);

            return(CreateList(multiDataList));
        }
Example #7
0
 public RedisServerApi(RedisConfiguration configuration)
 {
     _client = new RedisClient(new RedisEndpoint
     {
         Host     = configuration.Host,
         Port     = configuration.Port,
         Password = configuration.Password
     }).As <WorldServerDto>();
     _set = _client.Sets["WorldServer"];
 }
        /// <summary>
        /// Removes the connection from the connection list
        /// </summary>
        /// <param name="connection">The connection to remove</param>
        public Task RemoveAsync(T connection)
        {
            using (IRedisClient redisClient = RedisManager.GetClient())
            {
                IRedisTypedClient <T> redisTypedClient = redisClient.As <T>();
                IRedisSet <T>         items            = redisTypedClient.Sets[Key];
                items.Remove(connection);
            }

            return(Task.FromResult(0));
        }
Example #9
0
 public void Dispose()
 {
     redisHash      = null;
     redisKey       = null;
     redisList      = null;
     redisLock      = null;
     redisSet       = null;
     redisSortedSet = null;
     redisStore     = null;
     redisString    = null;
     redisSubscribe = null;
 }
Example #10
0
 public RedisHistoryService(Uri baseUri, bool resume)
 {
     using (var redisClient = new RedisClient())
     {
         this._redis   = redisClient.As <string>();
         this._history = this._redis.Sets[string.Format("barcodes:{0}:history", baseUri)];
         if (!resume)
         {
             this._history.Clear();
         }
     }
 }
 public RedisHistoryService(Uri baseUri, bool resume)
 {
     using (RedisClient redisClient = new RedisClient())
     {
         _redis   = redisClient.GetTypedClient <string>();
         _history = _redis.Sets[string.Format("barcodes:{0}:history", baseUri)];
         if (!resume)
         {
             _history.Clear();
         }
     }
 }
		public RedisHistoryService(Uri baseUri, bool resume)
		{
			using (RedisClient redisClient = new RedisClient())
			{
				_redis = redisClient.GetTypedClient<string>();
				_history = _redis.Sets[string.Format("barcodes:{0}:history", baseUri)];
				if (!resume)
				{
					_history.Clear();
				}
			}
		}
        /// <summary>
        /// Adds connection to the data store if the unique connection ID doesn't exist yet
        /// </summary>
        /// <param name="connection">The connection to add</param>
        public Task AddAsync(T connection)
        {
            using (IRedisClient redisClient = RedisManager.GetClient())
            {
                IRedisTypedClient <T> redisTypedClient = redisClient.As <T>();
                IRedisSet <T>         items            = redisTypedClient.Sets[Key];

                if (items.Count(x => x.ConnectionId == connection.ConnectionId) == 0)
                {
                    items.Add(connection);
                }
            }

            return(Task.FromResult(0));
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Task Clear()
        {
            using (IRedisClient redisClient = RedisManager.GetClient())
            {
                IRedisTypedClient <T> redisTypedClient = redisClient.As <T>();
                IRedisSet <T>         items            = redisTypedClient.Sets[Key];

                IEnumerable <T> connections = items.AsQueryable();
                foreach (T connection in connections)
                {
                    items.Remove(connection);
                }
            }

            return(Task.FromResult(0));
        }
        public void SetUp()
        {
            if (client != null)
            {
                client.Dispose();
                client = null;
            }
            client = new RedisClient(TestConfig.SingleHost);
            client.FlushAll();

            redis = client.GetTypedClient <T>();

            Set  = redis.Sets[SetId];
            Set2 = redis.Sets[SetId2];
            Set3 = redis.Sets[SetId3];
        }
        public void Execute <T>(IRedisSet <T> command, T item)
        {
            if (!factory.IsEnabled)
            {
                return;
            }

            using (var connection = factory.Open())
            {
                if (connection.IsPassThrough)
                {
                    return;
                }

                command.Set(connection, item);
            }
        }
 public T GetRandomItemFromSet(IRedisSet <T> fromSet)
 {
     return(DeserializeValue(client.SRandMember(fromSet.Id)));
 }
 public void StoreDifferencesFromSet(IRedisSet <T> intoSet, IRedisSet <T> fromSet, params IRedisSet <T>[] withSets)
 {
     client.SDiffStore(intoSet.Id, fromSet.Id, withSets.ConvertAll(x => x.Id).ToArray());
 }
        public HashSet <T> GetDifferencesFromSet(IRedisSet <T> fromSet, params IRedisSet <T>[] withSets)
        {
            var multiDataList = client.SDiff(fromSet.Id, withSets.ConvertAll(x => x.Id).ToArray());

            return(CreateHashSet(multiDataList));
        }
 public void StoreUnionFromSets(IRedisSet <T> intoSet, params IRedisSet <T>[] sets)
 {
     client.SUnionStore(intoSet.Id, sets.ConvertAll(x => x.Id).ToArray());
 }
 public void StoreIntersectFromSets(IRedisSet <T> intoSet, params IRedisSet <T>[] sets)
 {
     client.SInterStore(intoSet.Id, sets.ConvertAll(x => x.Id).ToArray());
 }
 public bool SetContainsItem(IRedisSet <T> set, T item)
 {
     return(client.SIsMember(set.Id, SerializeValue(item)) == 1);
 }
 public long GetSetCount(IRedisSet <T> set)
 {
     return(client.SCard(set.Id));
 }
 public void PopulateWithDifferencesOf(IRedisSet <T> fromSet, params IRedisSet <T>[] withSets)
 {
     client.StoreDifferencesFromSet(this, fromSet, withSets);
 }
 public void MoveTo(T item, IRedisSet <T> toSet)
 {
     client.MoveBetweenSets(this, toSet, item);
 }
Example #26
0
 public ProxyService(IContext redisContext, IProxyGrabberSettingsService settings)
 {
     _redisContext = redisContext;
     _settings     = settings;
     _proxiesSet   = _redisContext.Collections.GetRedisSet <string>(CacheKeys.Proxy);
 }
		public void StoreDiff(IRedisSet fromSet, params IRedisSet[] withSets)
		{
			var withSetIds = withSets.ToList().ConvertAll(x => x.Id).ToArray();
			client.StoreDifferencesFromSet(setId, fromSet.Id, withSetIds);
		}
 public T PopItemFromSet(IRedisSet <T> fromSet)
 {
     return(DeserializeValue(client.SPop(fromSet.Id)));
 }
 public void AddItemToSet(IRedisSet <T> toSet, T item)
 {
     client.SAdd(toSet.Id, SerializeValue(item));
 }
        public HashSet <T> GetAllItemsFromSet(IRedisSet <T> fromSet)
        {
            var multiDataList = client.SMembers(fromSet.Id);

            return(CreateHashSet(multiDataList));
        }
		public void Move(string value, IRedisSet toSet)
		{
			client.MoveBetweenSets(setId, toSet.Id, value);
		}
 public void RemoveItemFromSet(IRedisSet <T> fromSet, T item)
 {
     client.SRem(fromSet.Id, SerializeValue(item));
 }
		private List<string> MergeSetIds(IRedisSet[] withSets)
		{
			var allSetIds = new List<string> { setId };
			allSetIds.AddRange(withSets.ToList().ConvertAll(x => x.Id));
			return allSetIds;
		}
 public void MoveBetweenSets(IRedisSet <T> fromSet, IRedisSet <T> toSet, T item)
 {
     client.SMove(fromSet.Id, toSet.Id, SerializeValue(item));
 }
		public HashSet<string> Diff(IRedisSet[] withSets)
		{
			var withSetIds = withSets.ToList().ConvertAll(x => x.Id).ToArray();
			return client.GetDifferencesFromSet(setId, withSetIds);
		}