You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using StackExchange;
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
|
|
|
|
|
namespace RedisStuy
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 全局操作命令学习
|
|
|
|
|
/// https://stackexchange.github.io/StackExchange.Redis/
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class RedisServerStudy:IDisposable
|
|
|
|
|
{
|
|
|
|
|
private IServer redisServer;
|
|
|
|
|
|
|
|
|
|
public RedisServerStudy()
|
|
|
|
|
{
|
|
|
|
|
redisServer = RedisHelper.GetDefaultRedisServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务器信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>服务器信息</returns>
|
|
|
|
|
public IGrouping<string,KeyValuePair<string,string>>[] RedisInfo()
|
|
|
|
|
{
|
|
|
|
|
var info = redisServer.Info();
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务器版本号
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Version RedisVersion()
|
|
|
|
|
{
|
|
|
|
|
var redisVersion = redisServer.Version;
|
|
|
|
|
return redisVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭服务器
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool RedisShutdown()
|
|
|
|
|
{
|
|
|
|
|
bool commandResult = false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
redisServer.Shutdown(ShutdownMode.Default, CommandFlags.None);
|
|
|
|
|
commandResult = true;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
commandResult = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ping命令
|
|
|
|
|
/// (连通测试)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TimeSpan RedisPing()
|
|
|
|
|
{
|
|
|
|
|
var timespan = redisServer.Ping(CommandFlags.None);
|
|
|
|
|
return timespan;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 配置管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
public KeyValuePair<string,string>[] RedisConfig()
|
|
|
|
|
{
|
|
|
|
|
return redisServer.ConfigGet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Echo
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RedisValue RedisClient(RedisValue message)
|
|
|
|
|
{
|
|
|
|
|
return redisServer.Echo(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前选定数据库中keys的大小
|
|
|
|
|
/// </summary>
|
|
|
|
|
public long RedisDatabaseSize(int databaseIndex=0)
|
|
|
|
|
{
|
|
|
|
|
return redisServer.DatabaseSize(databaseIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long RedisS()
|
|
|
|
|
{
|
|
|
|
|
return 0L;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|