Exemplo n.º 1
0
 public RedisIdentityStorage(
     string clusterName,
     IConnectionMultiplexer connections,
     TimeSpan? maxWaitBeforeStaleLock = null,
     int maxConcurrency = 200
 )
 {
     RedisKey baseKey = clusterName + ":";
     _clusterIdentityKey = baseKey.Append("ci:");
     _memberKey = baseKey.Append("mb:");
     _connections = connections;
     _maxLockTime = maxWaitBeforeStaleLock ?? TimeSpan.FromSeconds(5);
     _asyncSemaphore = new AsyncSemaphore(maxConcurrency);
 }
Exemplo n.º 2
0
 protected RedisMutiKey(IDatabase database, string baseKey)
 {
     if (string.IsNullOrWhiteSpace(baseKey))
     {
         throw new ArgumentNullException(nameof(baseKey));
     }
     this.Database = database;
     if (!baseKey.EndsWith(":"))
     {
         baseKey = baseKey + ":";
     }
     this.BaseKey         = baseKey;
     this._indexSet       = new RedisSet <TKey> (database, BaseKey.Append(IndexSetName));
     this._expireIndexSet = new RedisSet <TKey> (database, BaseKey.Append(ExpireIndexSetName));
 }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public async Task AddProduct(Product item)
        {
            IDatabase database = _context.Connection.GetDatabase();
            string    pattern  = "Product:" + item.ProductId.Trim();
            RedisKey  key      = new RedisKey().Append(pattern);

            await database.StringSetAsync(key, item.ProductId);

            await database.StringSetAsync(key.Append(":price"), item.Price);

            await database.StringSetAsync(key.Append(":quantity"), item.Quantity);

            await database.StringSetAsync(key.Append(":specs"), item.Specification);

            await database.StringSetAsync(key.Append(":type"), item.Type);

            await database.StringSetAsync(key.Append(":category"), item.Category);
        }
Exemplo n.º 5
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");
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据条件查询 RedisKey
        /// </summary>
        /// <param name="database"></param>
        /// <param name="keyPrefix"></param>
        /// <returns></returns>
        public static RedisKey[] GetKeys(this IDatabase database, RedisKey keyPrefix)
        {
            if (string.IsNullOrEmpty(keyPrefix))
            {
                throw new ArgumentNullException(nameof(keyPrefix));
            }
            var partten = keyPrefix.Append("*");

            return((RedisKey[])database.Execute("KEYS", partten));
        }
Exemplo n.º 7
0
        private void setupRetrieveAll()
        {
            var key = new RedisKey();

            key = key.Append("notes_1");
            serverMock.Setup(x => x.Keys(0, notesPrefix + "*", 10, CommandFlags.None)).Returns(new List <RedisKey>()
            {
                key
            });
            dbMock.Setup(x => x.StringGetAsync(key.ToString(), CommandFlags.None)).ReturnsAsync("notes");
        }
Exemplo n.º 8
0
 /// <summary>
 /// 根据 Id 获取 RedisKey
 /// <see cref="RedisKey.Append"/>,生成 "{baseKey}:{id}" 的二级结构键值
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 protected RedisKey GetEntryKey(TKey key)
 {
     return(BaseKey.Append(key.ToString()));
 }
Exemplo n.º 9
0
 private RedisKey MemberKey(string memberId) => _memberKey.Append(memberId);
Exemplo n.º 10
0
 private RedisKey IdKey(ClusterIdentity clusterIdentity) => _clusterIdentityKey.Append(clusterIdentity.ToString());
Exemplo n.º 11
0
 /// <summary>
 /// 根据 Id 获取 RedisKey
 /// <see cref="RedisKey.Append"/>,生成 "{baseKey}:{id}" 的二级结构键值
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 protected RedisKey GetSubKey(string id)
 {
     return(BaseKey.Append(id));
 }
Exemplo n.º 12
0
 private static RedisKey GetDatasetRootNamespace(string datasetName)
 {
     return(rootKey.Append(datasetName));
 }