C# Redis Server分布式缓存编程(二)
2023-09-11 14:16:57 时间
在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<Phone> phones = redisClient.As<Phone>(); 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); } }
运行结果:
相关文章
- python操作redis用法详解
- [C#] c# 验证手机号码 最新的17手机号
- Redis 客户端 Jedis、lettuce 和 Redisson 对比
- C#Redis集合set
- 大厂标配的Redis,很多人却不知道它高性能的秘密……
- C# servicestack.redis 互通 java jedis
- Redis应用场景-转载
- Redis的Python客户端redis-py的初步使用
- Redis-Cluster实战--5.使用redis-cli安装
- Redis配置文件详解(redis.conf)
- redis集群之REDIS CLUSTER
- Atititt java redis jedis 使用 Redis体系 Redis 命令 Redis 命令Redis 键(key)Redis 字符串(String)Redis 哈希(Hash)R
- 【服务器安装Redis】Centos7离线安装redis
- 〖Python 数据库开发实战 - Python与Redis交互篇④〗- 利用 redis-py 实现集合与有序集合的常用指令操作
- 〖Python 数据库开发实战 - Python与Redis交互篇⑨〗- 利用 redis-py 实现模拟商品秒杀活动案例
- redis启动报错,需要关闭快照,报错-MISCONF Redis is configured to save RDB snapshots-解决
- C# 连接SQL Server数据库的几种方式--server+data source等方式
- (21)C# 访问Redis的测试
- c# redis系列一
- redis_05 _ 内存快照:宕机后,Redis如何实现快速恢复
- Redis 5.0 redis-cli --cluster help说明
- redis主从复制操作
- C# 中使用 Redis 简单存储
- Redis为什么默认16个数据库,干什么用?
- 【Redis】五大数据结构及其常用指令
- 【redis源码分析】Redis Sentinel 是如何实际解决分布式共识问题的