using System;
using StackExchange.Redis;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using System.Collections;
namespace CallCenter.Utility
{
public class RedisHelper
{
#region
//执行顺序---静态字段---静态构造函数---构造函数
private static ConnectionMultiplexer redis;
private static IDatabase database;
static RedisHelper()
{
if (redis == null || !redis.IsConnected)
{
redis = ConnectionMultiplexer.Connect(Configs.GetValue("Redis_Server")+":"+Configs.GetValue("Redis_Port"));
//redis = ConnectionMultiplexer.Connect("192.168.4.18, abortConnect=false");
database = redis.GetDatabase(int.Parse(Configs.GetValue("Redis_Defaultdatabase")));
// database = redis.GetDatabase(10);
}
}
#endregion
#region redis 字符串(string)操作
///
/// 设置指定键的值
///
///
///
///
public static bool StringSet(string key, string value)
{
return database.StringSet(key, value);
}
///
/// 获取指定键的值
///
///
///
public static object StringGet(string key)
{
var rt= database.StringGet(key);
if (rt.IsNull)
{
return null;
}
else
{
return rt;
}
}
///
/// 获取存储在键上的字符串的子字符串
///
///
///
///
///
public static object StringGet(string key, int start, int end)
{
var rt = database.StringGetRange(key, start, end);
if (rt.IsNull)
{
return null;
}
else
{
return rt;
}
}
///
/// 设置键的字符串值并返回其旧值
///
///
///
///
public static object StringGetAndSet(string key, string value)
{
var rt = database.StringGetSet(key, value);
if (rt.IsNull)
{
return null;
}
else
{
return rt;
}
}
///
/// 返回在键处存储的字符串值中偏移处的位值
///
///
///
///
public static bool StringGetBit(string key, long offset)
{
return database.StringGetBit(key, offset);
}
///
/// 获取所有给定键的值
///
///
///
public static List