前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C#进行Redis操作

C#进行Redis操作

作者头像
sparkexpert
发布2022-05-07 14:36:15
3420
发布2022-05-07 14:36:15
举报
文章被收录于专栏:大数据智能实战

由于一些程序是用.net来写的,刚好要访问以前的redis库,于是就找一些redis的.net客户端。

在redis主页上,提供了好多个利用.net封装redis的库:

csredis

Async (and sync) client for Redis and Sentinel

Nhiredis

A lightweight wrapper around the C client hiredis.

redis-sharp

redisboost

Thread-safe async Redis client. Offers high performance and simple api

ServiceStack.Redis

This is a fork and improvement of the original C# client written by Miguel De Icaza.

Sider

Minimalistic client for C#/.NET 4.0

StackExchange.Redis

This .NET client was developed by Stack Exchange for very high performance needs (replacement to the earlier BookSleeve).

TeamDev Redis Client

Redis Client is based on redis-sharp for the basic communication functions, but it offers some differences.

看了下各个的比较,最终选择排名第一的csredis。一看例子,非常简单,就它了。

下载后编译一测试,果然代码非常简洁易读。

如进行如下代码的执行:

 private void SetRediskey()         {             using (var redis = new RedisClient("localhost"))             {                 string ping = redis.Ping();                 string echo = redis.Echo("hello world");                 DateTime time = redis.Time();                 Console.WriteLine(ping);                 Console.WriteLine(echo);                 Console.WriteLine(time);                 redis.StartPipeTransaction();                 redis.Set("key", "value");                 redis.Set("key2", "value2");                 object[] result2 = redis.EndPipe(); // transaction is EXEC'd automatically if DISCARD was not called first                 foreach (object c in result2)                     Console.WriteLine("redis result:" + c.ToString());             }         }

输出结果为:

PONG hello world 04/16/2016 02:31:31 redis result:OK redis result:OK

而在redis端进行查询,效果如下:非常简单。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-04-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档