如何在redis存取值 redis取值和存值

主机教程 建站分享 2年前 (2022-09-20) 225次浏览

文章摘要:如何在redis存取值 redis取值和存值

在redis存取值的示例: //redis缓存 存值 [Route("api/cunzhi")] [HttpG […]

在redis存取值的示例:

//redis缓存 存值

[Route("api/cunzhi")]

[HttpGet]

public IHttpActionResult a(string pname, string address)

{

List projects = new List { new tb_ProcInfo {Pname=pname,Address=address } };

RedisClient client = new RedisClient("127.0.0.1", 6379);

for (int i = 0; i < projects.Count; i++)

{

client.EnqueueItemOnList("key", JsonConvert.SerializeObject(projects[i]));

}

return Ok(1);

}

//redis缓存 读取值

[Route("api/redis")]

[HttpGet]

public IHttpActionResult redis()

{

RedisClient client1 = new RedisClient("127.0.0.1", 6379);

var rlist = client1.LRange("key", 0, -1);

List list = new List();

foreach (var item in rlist)

{

string b = Encoding.UTF8.GetString(item);

tb_ProcInfo model = JsonConvert.DeserializeObject(b);

list.Add(model);

}

return Ok(list);

}


声明:
若非注明,本站文章源于互联网收集整理和网友分享发布,如有侵权,请联系站长处理。
文章名称:如何在redis存取值 redis取值和存值
文章链接:http://www.7966.org/post/15457.html
转载请注明出处

喜欢 (0)