方法一:单服务器
代码:
RedisClient redisClient = new RedisClient("127.0.0.1");
using (var redisUsers = redisClient.GetTypedClient<User>())
using (var redisBlogs = redisClient.GetTypedClient<Blog>())
{
//Create the user, getting a unique User Id from the User sequence.
/*var mythz = new User { Id = redisUsers.GetNextSequence(), Name = "Demis Bellot" };
//create some blogs using unique Ids from the Blog sequence. Also adding references
for (int i = 0; i < 1000; i++)
{
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" },
},
};
//Add the blog references
mythzBlogs.ForEach(x => mythz.BlogIds.Add(x.Id));
//Store the user and their blogs