Ejemplo n.º 1
0
        public async Task <byte[]> GetAsync(RedisKey key, CancellationToken cancellationToken = default)
        {
            _keyMemory?.Add(key);

            using (_requestTime.Measure())
                return(await _database.StringGetAsync(key.Prepend(_keyPrefix)));
        }
Ejemplo n.º 2
0
        public void PrependAppend()
        {
            {
                // simple
                RedisKey key = "world";
                var      ret = key.Prepend("hello");
                Assert.Equal("helloworld", (string)ret);
            }

            {
                RedisKey key1 = "world";
                RedisKey key2 = Encoding.UTF8.GetBytes("hello");
                var      key3 = key1.Prepend(key2);
                Assert.True(object.ReferenceEquals(key1.KeyValue, key3.KeyValue));
                Assert.True(object.ReferenceEquals(key2.KeyValue, key3.KeyPrefix));
                Assert.Equal("helloworld", (string)key3);
            }

            {
                RedisKey key = "hello";
                var      ret = key.Append("world");
                Assert.Equal("helloworld", (string)ret);
            }

            {
                RedisKey key1 = Encoding.UTF8.GetBytes("hello");
                RedisKey key2 = "world";
                var      key3 = key1.Append(key2);
                Assert.True(object.ReferenceEquals(key2.KeyValue, key3.KeyValue));
                Assert.True(object.ReferenceEquals(key1.KeyValue, key3.KeyPrefix));
                Assert.Equal("helloworld", (string)key3);
            }
        }
Ejemplo n.º 3
0
        public KeyValuePair <byte[], IEnumerable <byte[]> > GetReduceTask()
        {
            RedisKey key    = CurrentTask;
            string   prefix = "kv_" + JobId + "_";
            var      vals   = db.ListRange(key.Prepend(prefix));

            return(new KeyValuePair <byte[], IEnumerable <byte[]> >(key, vals.Select(v => (byte[])v)));
        }
Ejemplo n.º 4
0
        public void TestRedisKey()
        {
            RedisKey key        = "1";
            RedisKey anotherKey = key.Append("2");
            var      t          = anotherKey.Prepend("3");

            Assert.IsTrue(anotherKey == "12");
            Assert.IsTrue(t == "312");
        }
Ejemplo n.º 5
0
        public void FinishReduceTask(byte[] result, CompletionTrigger trigger = null)
        {
            string id = JobId;

            db.ListRightPush("out_" + id, result);

            RedisKey taskKey = CurrentTask;
            string   prefix  = "kv_" + JobId + "_";

            db.KeyDelete(taskKey.Prepend(prefix));
            CurrentTask = null;

            var counter = db.HashDecrement("counters", "reduce_" + id);

            if (counter <= 0 && trigger != null)
            {
                trigger(id);
            }
        }
Ejemplo n.º 6
0
        public IDictionary <RedisKey, MockRedisValueWithExpiry> GetDbWithExpiry()
        {
            Dictionary <RedisKey, MockRedisValueWithExpiry> dict = new Dictionary <RedisKey, MockRedisValueWithExpiry>();
            var database = GetDatabase();

            foreach (RedisKey key in GetKeys())
            {
                string stringKey = key;
                stringKey = stringKey.Substring(ContentLocationStoreFactory.DefaultKeySpace.Length);
                RedisKey redisKey = stringKey;
                redisKey = redisKey.Prepend(ContentLocationStoreFactory.DefaultKeySpace);
                if (!dict.ContainsKey(redisKey))
                {
                    var type = database.KeyType(key);
                    if (type != RedisType.String)
                    {
                        continue;
                    }

                    var      valueWithExpiry = database.StringGetWithExpiry(key);
                    DateTime?expiryDate;
                    if (valueWithExpiry.Expiry == null)
                    {
                        expiryDate = null;
                    }
                    else if (valueWithExpiry.Expiry.Value == default(TimeSpan))
                    {
                        expiryDate = null;
                    }
                    else
                    {
                        expiryDate = _clock.UtcNow + valueWithExpiry.Expiry;
                    }

                    dict[redisKey] = new MockRedisValueWithExpiry(valueWithExpiry.Value, expiryDate);
                }
            }

            return(dict);
        }
 private static RedisKey GetKey(RedisKey key)
 {
     return(key.Prepend(DefaultKeySpace));
 }