博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# Redis Server分布式缓存编程(二)(转)
阅读量:7195 次
发布时间:2019-06-29

本文共 1914 字,大约阅读时间需要 6 分钟。

出处;http://www.cnblogs.com/davidgu/p/3263485.html

在Redis编程中, 实体和集合类型则更加有趣和实用

namespace Zeus.Cache.Redis.Demo{    public class Person    {        public int Id { get; set; }        public string Name { get; set; }        public string Surname { get; set; }        public int Age { get; set; }        public string Profession { get; set; }    }}
namespace Zeus.Cache.Redis.Demo{    public class Phone    {        public int Id { get; set; }        public string Model { get; set; }        public string Manufacturer { get; set; }        public Person Owner { get; set; }    }}
public void EntityDemo()        {            using (RedisClient redisClient = new RedisClient(host))            {                IRedisTypedClient
phones = redisClient.As
(); Phone phoneFive = phones.GetValue("5"); if (phoneFive == null) { // make a small delay Thread.Sleep(2000); // creating a new Phone entry phoneFive = new Phone { Id = 5, Manufacturer = "Nokia", Model = "Lumia 200", Owner = new Person { Id = 1, Age = 90, Name = "OldOne", Profession = "sportsmen", Surname = "OldManSurname" } }; // adding Entry to the typed entity set phones.SetEntry(phoneFive.Id.ToString(), phoneFive); } string message = "Phone model is " + phoneFive.Manufacturer; message += "\nPhone Owner Name is: " + phoneFive.Owner.Name; Console.WriteLine(message); } }

运行结果:

 

你可能感兴趣的文章
什么是.Net的异步机制(线程间通信) - step 5
查看>>
Lambda应用设计模式
查看>>
解决svn异常报错“”cleanup failed to process the following paths …… previous operation has not finished”...
查看>>
富文本框--FreeTextBox的使用
查看>>
koa2使用阿里云oss的nodejs sdk实现上传图片
查看>>
简单select(2)
查看>>
pandas基础学习
查看>>
用实例一步步教你写Jquery插件
查看>>
Qt资源整理ING
查看>>
看看checksec
查看>>
1. Two Sum
查看>>
MySQL基础之 标准模式通配符
查看>>
聊一聊python的单例模式
查看>>
第十一篇、RxSwift
查看>>
复分析学习9——全纯函数各阶导数在紧集上的一致估计
查看>>
run_test() 验证平台的入口
查看>>
PHP网站,两个域名在一个空间,如何做301转向
查看>>
Mysql系列五:数据库分库分表中间件mycat的安装和mycat配置详解
查看>>
Web References - There was an error downloading 'http://localhost:/xxx/xxx.asmx'
查看>>
Python之禅及释义
查看>>