public void TestAdd()
        {
            var instance = Model.CreateNew();

            dict.Add(instance.Str, instance);
            Assert.True(dict.ContainsKey(instance.Str));
            var serialized = dict[instance.Str];

            Assert.Equal(instance, serialized);
        }
Beispiel #2
0
        /// <summary>
        /// 同时设置哈希表 <paramref name="key"/> 中一个或多个域值。
        /// </summary>
        /// <param name="client">Redis 客户端。</param>
        /// <param name="key">键名</param>
        /// <param name="fieldValues">域值的匿名对象。</param>
        /// <returns>结果。</returns>
        public static Result HMSet(this IRedisClient client, string key, object fieldValues)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (fieldValues == null)
            {
                throw new ArgumentNullException(nameof(fieldValues));
            }
            RedisDictionary redisDict;

            if (fieldValues is System.Collections.IDictionary)
            {
                redisDict = new RedisDictionary(fieldValues as System.Collections.IDictionary);
            }
            else
            {
                var typeMapper = TypeMapper.Create(fieldValues.GetType());
                redisDict = new RedisDictionary(typeMapper.Count);
                foreach (var propertyMapper in typeMapper.Properties)
                {
                    redisDict.Add(propertyMapper.Name, BinaryValue.Create(propertyMapper.GetValue(fieldValues, false), propertyMapper.Property));
                }
            }
            return(HMSet(client, key, redisDict));
        }
Beispiel #3
0
 private void RecordTripOriginatingAndServicingPartner(DispatchTripRequest r, Gateway partner)
 {
     originatingPartnerByTrip.Add(r.tripID, r.clientID);
     Logger.AddTag("Originating partner", r.clientID);
     servicingPartnerByTrip.Add(r.tripID, partner.ID);
     Logger.AddTag("Servicing partner", partner.name);
 }
Beispiel #4
0
        public static Task SetAsync <TValue>(RedisDictionary <string, Crap> _dictionary, string key, TValue value)
        {
            _dictionary.Add(key, new Crap {
                Value = value
            });

            return(Task.CompletedTask);
        }
Beispiel #5
0
        public static void AddToDictionary(string command, RedisDictionary redisDictionary)
        {
            int wordStartIndex = command.IndexOf(' ') + 1;
            int wordEndIndex = command.IndexOf('-');

            string word = command.Substring(wordStartIndex, wordEndIndex - wordStartIndex).Trim();
            string explination = command.Substring(wordEndIndex + 1, (command.Length - 1) - wordEndIndex);

            redisDictionary.Add(word, explination);
        }
Beispiel #6
0
 List <Zone> GetPartnerCoverage(string partnerID)
 {
     if (!partnerCoverage.ContainsKey(partnerID))
     {
         Gateway partner = partners[partnerID];
         Gateway.GetPartnerInfoResponse resp = partner.GetPartnerInfo(new Gateway.GetPartnerInfoRequest(ID));
         List <Zone> coverage = new List <Zone>();
         foreach (Fleet f in resp.fleets)
         {
             coverage.AddRange(f.Coverage);
         }
         partnerCoverage.Add(partner.ID, coverage);
     }
     return(partnerCoverage[partnerID]);
 }
Beispiel #7
0
 public void Add(string id, Trip trip)
 {
     dict.Add(id, trip);
 }
Beispiel #8
0
        public static Task SetAsyncX <TValue>(RedisDictionary <string, object> _dictionary, string key, TValue value)
        {
            _dictionary.Add(key, value);

            return(Task.CompletedTask);
        }
Beispiel #9
0
        public void TestScan()
        {
            var reply1 = "*2\r\n$1\r\n0\r\n*3\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n$5\r\ntest3\r\n";
            var reply2 = "*2\r\n$1\r\n0\r\n*0\r\n";
            var reply3 = "*2\r\n$1\r\n0\r\n*0\r\n";
            var reply4 = "*2\r\n$1\r\n0\r\n*0\r\n";
            using(var mock = new MockConnector("localhost", 9999, reply1, reply2, reply3, reply4))
            using(var redis = new RedisClient(mock))
            {
                var resp = (redis.Scan(0) as RedisScan<string>).GetEnumerator() as RedisScan<string>.Enumerator;
                for(int i = 0; i < 3; i++)
                {
                    resp.MoveNext();
                    Assert.Equal(3 - i - 1, resp.Items.Length);
                    Assert.Equal(0, resp.Cursor);
                    Assert.Equal("test" + (i + 1), resp.Current);
                }
                Assert.Equal("*2\r\n$4\r\nSCAN\r\n$1\r\n0\r\n", mock.GetMessage());

                redis.Scan(1, pattern: "pattern").ToArray();
                Assert.Equal("*4\r\n$4\r\nSCAN\r\n$1\r\n1\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n", mock.GetMessage());

                redis.Scan(2, count: 5).ToArray();
                Assert.Equal("*4\r\n$4\r\nSCAN\r\n$1\r\n2\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());

                redis.Scan(3, pattern: "pattern", count: 5).ToArray();
                Assert.Equal("*6\r\n$4\r\nSCAN\r\n$1\r\n3\r\n$5\r\nMATCH\r\n$7\r\npattern\r\n$5\r\nCOUNT\r\n$1\r\n5\r\n", mock.GetMessage());
            }


            this.RealCall(redis =>
            {
                var dict = new RedisDictionary();
                for(int i = 1; i < 21; i++)
                {
                    dict.Add("key" + i, "value" + i);
                }
                redis.MSet(dict);
                Assert.Equal(20, redis.Scan().Count());
            });
        }
        public Task Add(ReadModelHandler item)
        {
            _readModelHandlers.Add(item.ReadmodelType, item);

            return(Task.FromResult(0));
        }