public async Task SetAdd() { var set = new RedisSet<int>(GlobalSettings.Default, "set"); await set.Delete(); (await set.Add(1)).Is(true); (await set.Add(10)).Is(true); (await set.Add(1)).Is(false); (await set.Contains(1)).IsTrue(); (await set.Contains(1000)).IsFalse(); (await set.Members()).OrderBy(x => x).Is(1, 10); (await set.Length()).Is(2); var set2 = new RedisSet<MySetTestClass[]>(GlobalSettings.Default, "set2"); await set2.Delete(); (await set2.Add(new[] { new MySetTestClass { MyProperty = 100 }, new MySetTestClass { MyProperty = 300 } })).Is(true); (await set2.Add(new[] { new MySetTestClass { MyProperty = 500 }, new MySetTestClass { MyProperty = 900 } })).Is(true); (await set2.Add(new[] { new MySetTestClass { MyProperty = 100 }, new MySetTestClass { MyProperty = 300 } }, TimeSpan.FromSeconds(1))).Is(false); (await set2.Members()).SelectMany(xs => xs, (xs, x) => x.MyProperty).OrderBy(x => x).Is(100, 300, 500, 900); await Task.Delay(TimeSpan.FromMilliseconds(1500)); (await set.Exists()).IsTrue(); (await set2.Exists()).IsFalse(); }
/// <summary> /// 初始化数据库环境、实例化子类中,所有Set属性 /// </summary> public void Initializer() { if (IsInitializer) { return; } _client = new RedisClient(_redisConnection); IsInitializer = true; Connection = new RedisConnection(_client); Hash = new RedisHash(_client); Key = new RedisKey(_client); List = new RedisList(_client); PubSub = new RedisPubSub(_client); Script = new RedisScript(_client); Server = new RedisServer(_client); Set = new RedisSet(_client); SortedSet = new RedisSortedSet(_client); String = new RedisString(_client); Transaction = new RedisTransaction(_client); Bit = new RedisBit(_client); Expire = new RedisExpire(_client); Sort = new RedisSort(_client); Number = new RedisNumber(_client); }
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)); }
public async Task SetPop() { var set = new RedisSet<int>(GlobalSettings.Default, "set"); await set.Delete(); (await set.Add(1)).Is(true); (await set.Add(10)).Is(true); var p1 = await set.Pop(); p1.HasValue.IsTrue(); var p2 = await set.Pop(); p2.HasValue.IsTrue(); (await set.Pop()).HasValue.IsFalse(); new[] { p1.Value, p2.Value }.OrderBy(x => x).Is(1, 10); }
public static List <ScoringFunctionResult> GetRandomProducts(int count, WebSites webSite, AggregateFilter filters, ContentTypeQuota quota) { Log.Debug("ProductDataAccess.GetRandomItems", "parameters", count, webSite); string queryUniquestring; IMongoQuery query = GetQuery(webSite, quota, filters, out queryUniquestring); RedisSet <string> cache = GetRedisSet(query, queryUniquestring); var set = cache.GetRandomItems(count, x => x); return(quota != null?set.Select(sfr => new ScoringFunctionResult() { ItemId = int.Parse(sfr), QuotaId = quota.Id }).ToList() : set.Select(sfr => new ScoringFunctionResult() { ItemId = int.Parse(sfr) }).ToList()); }
public async Task SetPop() { var set = new RedisSet <int>(GlobalSettings.Default, "set"); await set.Delete(); (await set.Add(1)).Is(true); (await set.Add(10)).Is(true); var p1 = await set.Pop(); p1.HasValue.IsTrue(); var p2 = await set.Pop(); p2.HasValue.IsTrue(); (await set.Pop()).HasValue.IsFalse(); new[] { p1.Value, p2.Value }.OrderBy(x => x).Is(1, 10); }
public async Task SetAdd() { var set = new RedisSet <int>(GlobalSettings.Default, "set"); await set.Delete(); (await set.Add(1)).Is(true); (await set.Add(10)).Is(true); (await set.Add(1)).Is(false); (await set.Contains(1)).IsTrue(); (await set.Contains(1000)).IsFalse(); (await set.Members()).OrderBy(x => x).Is(1, 10); (await set.Length()).Is(2); var set2 = new RedisSet <MySetTestClass[]>(GlobalSettings.Default, "set2"); await set2.Delete(); (await set2.Add(new[] { new MySetTestClass { MyProperty = 100 }, new MySetTestClass { MyProperty = 300 } })).Is(true); (await set2.Add(new[] { new MySetTestClass { MyProperty = 500 }, new MySetTestClass { MyProperty = 900 } })).Is(true); (await set2.Add(new[] { new MySetTestClass { MyProperty = 100 }, new MySetTestClass { MyProperty = 300 } }, TimeSpan.FromSeconds(1))).Is(false); (await set2.Members()).SelectMany(xs => xs, (xs, x) => x.MyProperty).OrderBy(x => x).Is(100, 300, 500, 900); await Task.Delay(TimeSpan.FromMilliseconds(1500)); (await set.Exists()).IsTrue(); (await set2.Exists()).IsFalse(); }
public async Task <ActionResult <List <RedisSet> > > GetKeys() { var connection = connectionProvider.TryGetConnection("test"); var keys = new List <RedisSet>(); foreach (var endPoint in connection.GetEndPoints()) { var server = connection.GetServer(endPoint); var serverKeys = server.KeysAsync(); await foreach (var key in serverKeys) { var set = new RedisSet { Key = key, Type = (await connection.GetDatabase().KeyTypeAsync(key)).ToString() }; keys.Add(set); } } return(keys); }
private static RedisSet <string> GetRedisSet(IMongoQuery query, string queryUniqueString) { try { Log.Debug("ProductDataAccess.GetRedisSet", "Accessing redis with key", queryUniqueString); RedisSet <string> cache = new RedisSet <string>(RedisSetWorkspace, queryUniqueString); if (!cache.IsSetExists()) { // ids of items var ids = new List <string>(); var products = _mongoContext.GetDocuments <BsonDocument>(query, _collectionName, new string[] { ProductIdField, MongoTypeField }, Limit); Log.Debug("ProductDataAccess.GetRedisSet", "Get query items", queryUniqueString, _collectionName, query, _collectionName, ProductIdField, MongoTypeField, Limit); if (products != null && products.Any()) { ids.AddRange(products.Select(doc => doc.GetValue(ProductIdField).ToString())); if (Logger.Current.IsDebugEnabled) { Log.Debug("ProductDataAccess.GetRedisSet", "ids found", _collectionName, query, queryUniqueString, string.Join(",", ids.Select(id => id))); } } else { Log.Debug("ProductDataAccess.GetRedisSet", "No products in mongo db", _collectionName, query, queryUniqueString); } // filling cache cache.AddRange(ids); } return(cache); } catch (Exception ex) { Log.Error("ProductDataAccess.GetRedisSet", "Exception when getting from mongo", query, ex); throw; } }
public RedisEncryptKeyWithSetStrategy(Encoding encoding, EncryptType entryptType = EncryptType.MD5) : base(encoding, entryptType) { _set = new RedisSet(); _key = new RedisKeys(); }
public RedisSetTest() { _set = new RedisSet(base.Database, SetKey); Assert.Empty(_set.Values); }