コード例 #1
0
        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;
            }
        }
コード例 #2
0
ファイル: RedisMutiKey.cs プロジェクト: zwq00000/Redis.Net
 /// <summary>
 /// 增加集合时调用此方法,更新索引
 /// </summary>
 /// <param name="keys"></param>
 /// <returns></returns>
 protected long AddKeyIndex(params TKey[] keys)
 {
     return(_indexSet.AddRange(keys));
 }