コード例 #1
0
ファイル: Program.cs プロジェクト: SimpleSimple/AspNetTest
        static void InsertTestData()
        {
            var redisUsers = client.As<User>();
            var redisBlogs = client.As<Blog>();
            var redisBlogPosts = client.As<BlogPost>();

            var yangUser = new User { Id = redisUsers.GetNextSequence(), Name = "Eric Yang" };

            var yangBlog = new Blog
            {
                Id = redisBlogs.GetNextSequence(),
                UserId = yangUser.Id,
                UserName = yangUser.Name,
                Tags = new List<string> { "Architecture", ".NET", "Databases" }
            };

            var blogPosts = new List<BlogPost>
            {
                new BlogPost
                {
                    Id = redisBlogPosts.GetNextSequence(),
                    BlogId = yangBlog.Id,
                    Title = "Memcache",
                    Categories = new List<string>{"NoSQL", "DocumentDB"},
                    Tags = new List<string>{"Memcache","NoSQL","JSON",".NET"},
                    Comments = new List<BlogPostComment>{
                        new BlogPostComment{Content="First Comment!",CreatedDate=DateTime.UtcNow},
                        new BlogPostComment{Content="Second Comment!",CreatedDate=DateTime.UtcNow}
                    }
                },
                new BlogPost
                {
                    Id = redisBlogPosts.GetNextSequence(),
                    BlogId = yangBlog.Id,
                    Title = "Cassandra",
                    Categories = new List<string> { "NoSQL", "Cluster" },
                    Tags = new List<string> {"Cassandra", "NoSQL", "Scalability", "Hashing"},
                    Comments = new List<BlogPostComment>
                    {
                        new BlogPostComment { Content = "First Comment!", CreatedDate = DateTime.UtcNow,}
                    }
                },
            };

            yangUser.BlogIds.Add(yangBlog.Id);
            yangBlog.BlogPostIds.AddRange(blogPosts.Where(x => x.BlogId == yangBlog.Id).Select(x => x.Id));

            redisUsers.Store(yangUser);
            redisBlogs.StoreAll(new[] { yangBlog });
            redisBlogPosts.StoreAll(blogPosts);

            //var mythzBlogs = new List<Blog> {
            //        new Blog
            //        {
            //            Id = redisBlogs.GetNextSequence(),
            //            UserId = mythz.Id,
            //            UserName = mythz.Name,
            //            Tags = new List<string> { "Architecture", ".NET", "Redis" },
            //        },
            //        new Blog
            //        {
            //            Id = redisBlogs.GetNextSequence(),
            //            UserId = mythz.Id,
            //            UserName = mythz.Name,
            //            Tags = new List<string> { "Music", "Twitter", "Life" },
            //        }
            //};

            //mythzBlogs.ForEach(x => mythz.BlogIds.Add(x.Id));

            //redisUsers.Store(mythz);
            //redisBlogs.StoreAll(mythzBlogs);

            //retrieve all blogs
            //var blogs = redisBlogs.GetAll();

            //Console.WriteLine(blogs.Dump());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: SimpleSimple/AspNetTest
        static void Show_list_of_blogs()
        {
            var redisUsers = client.As<User>();
            var redisBlogs = client.As<Blog>();
            var mythz = new User { Id = redisUsers.GetNextSequence(), Name = "Demis Bellot" };

            var mythzBlogs = new List<Blog> {
                    new Blog
                    {
                        Id = redisBlogs.GetNextSequence(),
                        UserId = mythz.Id,
                        UserName = mythz.Name,
                        Tags = new List<string> { "Architecture", ".NET", "Redis" },
                    },
                    new Blog
                    {
                        Id = redisBlogs.GetNextSequence(),
                        UserId = mythz.Id,
                        UserName = mythz.Name,
                        Tags = new List<string> { "Music", "Twitter", "Life" },
                    }
            };

            mythzBlogs.ForEach(x => mythz.BlogIds.Add(x.Id));

            redisUsers.Store(mythz);
            redisBlogs.StoreAll(mythzBlogs);

            //retrieve all blogs
            var blogs = redisBlogs.GetAll();

            Console.WriteLine(blogs.Dump());
        }