TeamDev Redis Client

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介:
TeamDev Redis Client is a c# Client for  Redis .
Redis is an advanced key-value store that supports many features and that focuses on performance. 

Redis Client is based on  redis-sharp  for the basic communication functions, but it offers some differences, 
a better abstraction from the Redis Protocol, and an usability more close to .Net standard objects in managing Hashes, Sets, Lists and keys. 
Unlike redis-sharp it also supports all commands of Redis up to version 2.2.5

TeamDev Redis Client is not just another provider for Redist : 
it introduces a  DocumentStore  to simplify data management in a  mixed-environment  where you have  some data stored in a relational database and some data stored in Redis .
This will help you to integrate two different ways of managing data without changing your data structure. 

With this important feature you can : 
  • Store an Entity in a relational DataBase AND in Redis (ex: for caching purpose) without too much code.
  • Move an Entity from the relational DataBase to Redis and Vice-Versa.
  • Store a part of an entity in the relational DataBase and a part of the same entity in Redis.
  • Use Redis to store complex objects

It's compatible with all kinds of Entities including  LinqToSql EntityFramework NHibernate  and all kind of Object Relational Mappers (ORM) that use a Class to manage data. 

The communication layer has been rewritten according to the new Unified Protocol introduced in version 1.2. 

And now some examples:

Base usage

      var redis = new RedisDataAccessProvider();

      redis.SendCommand(RedisCommand.SET, "mykey", "myvalue");
      redis.WaitComplete();


In RedisCommand enum you will find all supported Redis' commands. 
The provider helps you with some basic Helpers to access all data structures supported in redis. 

List example:

 // Clear the list
 redis.List["test"].Clear();

// Append a value
 redis.List["test"].Append(i.ToString());

// Count items
  var cc = redis.List["test"].Count;

// Left Pop
var r = redis.List["test"].LeftPop();

// Get All Values in the list.
var range = redis.List["test"].Values;

Hash example:

       // Two way for Setting a value to an hash.
      // First way
      redis.Hash["myhash"].Set("myfield", "value");

      // Second way
      redis.Hash["myhash"]["myfield"] = "value";



      // reading the hash 
      var result = redis.Hash["myhash"]["myfield"];
      result = redis.Hash["myhash"].Get("myfield");


      // All fields in the hash 
      redis.Hash["myhash"].Keys;

      // All values in the hash 
      redis.Hash["myhash"].Values;

      // All key-value pairs in the hash 
      redis.Hash["myhash"].Items;

      redis.Hash["myhash"].ContainsKey("myfield");

You don't have to remember all syntax items of the server but you can use it in a more readable way. 
Helpers will let you access data structures in a way more close to .Net Objects. 
So if you want to set a key in the store, you can do it more pratically just like setting a key-value structure or you can use the redis command directly. 

redis.Keys["key"] = "value";

or
redis.SendCommand(RedisCommand.SET, "key", "value");
redis.WaitComplete();



The client supports 
  • Hashes
  • Sets
  • SortedSets
  • Keys
  • Lists

You can access structure's helpers via the properties in the provider. 

Document Store

The Document Store is the new feature introduced to help integrations between relational datas and non relational datas. 

Usually, in modern data access design, you have a model of classes to manage data, and you will use some kind of ORM to access DataBase and to 
persist and retrieve the objects from database. 
ORM usually helps you to write query and filters using some kind of languages. 

In some scenarios it's not convenient to store data in a RDBMS, but some data can be easly persisted in a key-value store. 
If this values are part of an entity you will have to manage data access manually and to persist and retrieve data manually. 
Documet Store  does this job for you. 
It will help you to store data in a key-value way without give to you the work of accessing the store. 

How does it work:

First of all we need a key to store data ( the store is a KEY-VALUE store, so we need a key)
Usually you already have the key, and it's stored on your entity as property. 

All you have to do is to decorate the property that will contain the key value with the  DocumentStoreKeyAttribute

public class myEntity
{
    [DocumentStoreKey]
    public string mykeyproperty { get; set;}
}



After that you can use the DocumentStore on the "myEntity" to store the entire Entity on Redis. 

 var store = DocumentStore.New;
 store.Set(theentity);



or you can store list of entities in one command

  var store = DocumentStore.New;
  List<myEntity> entities = new List<myEntity>();

  ... omissis ...

 store.Set(entities);



To retrieve datas you havo only to do the same , but a different command

 var store = DocumentStore.New;
 store.Get<myEntity>( "100"); // where "100" is the value contained in the property key when we have saved the entity. 



If you have to save the entity on the RDBMS and only a part of the entity in Redis, 
you have to decorate the property that you have to save in Redis with the attribute  DocumentValueAttribute
and you have to use the command  PartialSet  and  PartialGet  to manage the data. 


In the following picture you can see the base classes of the provider. 

redis.png

you can contact us at: 
Teamdev

you can follow us on twitter :
TeamDevPerugia
Paolo Possanzini
Andrea Cruciani


or you can visit our web site: 





本文作者:陈群
本文来自云栖社区合作伙伴rediscn,了解相关信息可以关注redis.cn网站。
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
3月前
|
NoSQL 网络协议 Linux
Redis的实现一:c、c++的网络通信编程技术,先实现server和client的通信
本文介绍了使用C/C++进行网络通信编程的基础知识,包括创建socket、设置套接字选项、绑定地址、监听连接以及循环接受和处理客户端请求的基本步骤。
66 6
|
3月前
|
存储 监控 NoSQL
Redis的实现二: c、c++的网络通信编程技术,让服务器处理多个client
本文讨论了在C/C++中实现服务器处理多个客户端的技术,重点介绍了事件循环和非阻塞IO的概念,以及如何在Linux上使用epoll来高效地监控和管理多个文件描述符。
42 0
|
NoSQL Java Redis
redis.clients.jedis.exceptions.JedisDataException: ERR Syntax error, try CLIENT (LIST | KILL ip:port
redis.clients.jedis.exceptions.JedisDataException: ERR Syntax error, try CLIENT (LIST | KILL ip:port
|
8月前
|
NoSQL 安全 Linux
Another Redis Desktop Manager远程连接Redis报错:Client On Error: Error: connect ETIMEDOUT
在尝试使用Another Redis Desktop Manager连接远程Redis时遇到持续Timeout的问题,检查并执行了常规教程中的所有步骤,包括修改Redis配置文件以允许远程访问,开放本地防火墙的6379端口,以及确保网络连通性。
322 0
|
NoSQL 安全 Redis
【Redis异常】redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password
【Redis异常】redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password
301 0
|
NoSQL Redis
redis client连接数过多,大量空闲连接无法释放
redis client连接数过多,大量空闲连接无法释放
470 0
|
监控 NoSQL Redis
Redis 源码分析客户端数据结构(client)(下)
Redis 源码分析客户端数据结构(client)
463 0
Redis 源码分析客户端数据结构(client)(下)
|
NoSQL Java Redis
SpringBoot项目连接Redis:ERR Client sent AUTH, but no password is set
SpringBoot项目连接Redis:ERR Client sent AUTH, but no password is set
606 0
SpringBoot项目连接Redis:ERR Client sent AUTH, but no password is set
|
存储 开发框架 缓存
教你写个简单的Redis Client框架-.NET Core
教你写个简单的Redis Client框架-.NET Core
215 0
|
NoSQL 网络协议 Redis
Redis 源码分析客户端数据结构(client)(上)
Redis 源码分析客户端数据结构(client)
302 0