using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using ServiceStack.Redis;using System.Collections;using ServiceStack.Common;
public ActionResult Index() ?
{
? ? IEnumerator ie = hash.GetEnumerator(); ??
string hashtext = string.Empty; ??
? ? while (ie.MoveNext()) ??
? { ???
}
? ? ?
/* 大家对比下细节看看呢,上面操作的是副本,即便再次增加,内存中的内容也不会更新,而注释掉的就不一样了.而且,明显看书,是排序过的
//下面是发布订阅模型示例和命令行的几个命令示例
//最终实现完全同步
} ? Response.Write(hashtext);/*
?? }
//测试list的方法,随意放在控制器中,空视图即可
public string RedisList() ?
{ ?
byte[][] result = TestList(); ?
return result.ToString(); ?
private byte[][] TestList() ?
client.get,mget,set,mset,getset,hset,hget,sadd,sinter ,sinterstore等等都可以用了,亲测通过
//一个更复杂的例子:参照它可以实现和数据库的同步,而且,更重要的是,无需转化,只需组合封装,极为方便
public string testComplexDadaTable() ?
{ ??
DataTable dt = GetDataTable(); ??
var columns = dt.Columns; ???
var rows = dt.Rows; ???
List mydate = new List(); ?
for (int i = 0; i < rows.Count; i◆◆) ??
{ ???
?mydate.Add(test); ?
??? } ?
return null; ??? //
private DataTable GetDataTable() ?? { ??
? DataTable table = new DataTable(); ?
// Here we add five DataRows. ??
return table; ?? }
//为什么redis存储本质是流,如下示例:
mydate.Add(test); ???
string testby = test.ToString(); ??
byte[] arrtext = System.Text.Encoding.Default.GetBytes(testby); ??
} ??
private DataTable GetDataTable() ?
?DataTable table = new DataTable(); ?
return table; ??
注意:官方dll目前没有提供RedisClientHash类,需要用的话自己要从github拷贝下来加入工程(本实例没有用到),另外说明一点:只是hellworld没意思,所以给出了set示例,hash示例(没有参考任何文档,折腾死),测试大法好.
最后:
http://www.lvtao.net/book/redis.htm(中文手册)
以上过程掌握后,请阅读源代码.