前提在安装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