C#操作Redis

本文介绍了如何在C#环境中,通过NuGet包StackExchange.Redis来实现对Redis数据库的操作。首先确保已安装Redis,然后引入相关库,接着展示了一个封装好的Redis操作类,并提供了测试用例,展示了成功执行的结果。
摘要由CSDN通过智能技术生成

前提在安装Redis的情况下,不在赘述,上代码

NuGet引用Redis、StackExchange.Redis

封装类:

using ServiceStack.Redis;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RedisTest
{
    public class RedisCatcheHelper
    {
        private static readonly PooledRedisClientManager pool = null;
        private static readonly string[] redisHosts = null;
        public static int RedisMaxReadPool = 3;
        public static int RedisMaxWritePool = 1;
        static RedisCatcheHelper()
        {
            var redisHostStr = "127.0.0.1:6379";
            if (!string.IsNullOrEmpty(redisHostStr))
            {
                redisHosts = redisHostStr.Split(',');
                if (redisHosts.Length > 0)
                {
                    pool = new PooledRedisClientManager(redisHosts, redisHosts, new 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值