一、在Windows10下安装Redis
1、下载免安装的Redis版本。下载地址:https://github.com/MicrosoftArchive/redis/releases


2、在该文件夹下运行命令:
redis-server.exe redis.windows.conf

3、将redis安装成服务。运行redis-server.exe --service-install redis.windows.conf

4、使用命令行操作redis
set
:保存数据或修改数据,例 set name lily
get
: 取数据,例 get name
更多请参考:https://www.cnblogs.com/zqr99/p/7899701.html
二、在.Net Core 2.1中使用
1、安装依赖包:Nugget: StackExchange.Redis
2、新建RedisHelper
类
public class RedisHelper
{
private ConnectionMultiplexer Redis { get; set; }
private IDatabase DB { get; set; }
public RedisHelper(string connection)
{
Redis = ConnectionMultiplexer.Connect(connection);
DB = Redis.GetDatabase();
}
/// <summary>
/// 增加/修改
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool SetValue(string key, string value)
{
return DB.StringSet(key, value);
}
/// <summary>
/// 查询
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string GetValue(string key)
{
return DB.StringGet(key);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool DeleteKey(string key)
{
return DB.KeyDelete(key);
}
}
3、在控制台中使用
RedisHelper redisHelper = new RedisHelper("127.0.0.1:6379");
string value = "测试数据";
bool testValue = redisHelper.SetValue("key", value);
string saveValue = redisHelper.GetValue("key");
Console.WriteLine(saveValue);
bool newValue = redisHelper.SetValue("key", "NewValue");
saveValue = redisHelper.GetValue("key");
Console.WriteLine(saveValue);
bool deleteKey = redisHelper.DeleteKey("key");
string empty = redisHelper.GetValue("key");
Console.WriteLine(empty);
Console.ReadKey();
三、开源Redis可视化软件 AnotherRedisDesktopManager
1、下载地址:https://github.com/qishibo/AnotherRedisDesktopManager
