参考博客https://www.cnblogs.com/qukaicheng/p/7514168.html写的

安装教程https://www.redis.net.cn/tutorial/3503.html

实现后的东西

跳到H盘;cd打开指定文件夹

执行命令:redis-server.exe redis.conf

这时候另启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了。

切换到redis目录下运行 redis-cli.exe -h 127.0.0.1 -p 6379 。

设置键值对 set myKey abc

取出键值对 get myKey

然后设置密码

获取密码 :127.0.0.1:6379> CONFIG get requirepas

设置密码:127.0.0.1:6379> CONFIG set requirepass "123"

然后连接后,验证密码:127.0.0.1:6379> AUTH "123";然后才能进行操作

结果如下:设置密码要重新验证:不然config get requirepass  找不到

c# 中应用:添加引用 ServiceStack.Redis 3.9.x Complete Library;代码是复制的

 public class RedisCacheHelper
{
private static readonly PooledRedisClientManager pool = null;
private static readonly string[] writeHosts = null;
private static readonly string[] readHosts = null;
public static int RedisMaxReadPool = int.Parse(ConfigurationManager.AppSettings["redis_max_read_pool"]);
public static int RedisMaxWritePool = int.Parse(ConfigurationManager.AppSettings["redis_max_write_pool"]); static RedisCacheHelper()
{
var redisWriteHost = ConfigurationManager.AppSettings["redis_server_write"];
var redisReadHost = ConfigurationManager.AppSettings["redis_server_read"];
if (!string.IsNullOrEmpty(redisWriteHost))
{
writeHosts = redisWriteHost.Split(',');
readHosts = redisReadHost.Split(',');
if (readHosts.Length > )
{
pool = new PooledRedisClientManager(writeHosts, readHosts,
new RedisClientManagerConfig()
{
MaxWritePoolSize = RedisMaxWritePool,
MaxReadPoolSize = RedisMaxReadPool, AutoStart = true
});
}
}
}
public static void Add<T>(string key, T value, DateTime expiry)
{
if (value == null)
{
return;
} if (expiry <= DateTime.Now)
{
Remove(key);
return;
} try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
r.Set(key, value, expiry - DateTime.Now);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "存储", key);
} } public static void Add<T>(string key, T value)
{
RedisCacheHelper.Add<T>(key, value, DateTime.Now.AddMinutes());
} public static void Add<T>(string key, T value, TimeSpan slidingExpiration)
{
if (value == null)
{
return;
} if (slidingExpiration.TotalSeconds <= )
{
Remove(key);
return;
}
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
r.Set(key, value, slidingExpiration);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "存储", key);
} } public static T Get<T>(string key)
{
if (string.IsNullOrEmpty(key))
{
return default(T);
}
T obj = default(T);
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
obj = r.Get<T>(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "获取", key);
}
return obj;
} public static void Remove(string key)
{
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
r.Remove(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "删除", key);
} } public static bool Exists(string key)
{
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
return r.ContainsKey(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "是否存在", key);
} return false;
} public static IDictionary<string, T> GetAll<T>(IEnumerable<string> keys) where T : class
{
if (keys == null)
{
return null;
}
keys = keys.Where(k => !string.IsNullOrWhiteSpace(k)); if (keys.Count() == )
{
T obj = Get<T>(keys.Single()); if (obj != null)
{
return new Dictionary<string, T>() { { keys.Single(), obj } };
} return null;
}
if (!keys.Any())
{
return null;
}
try
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
return r.GetAll<T>(keys);
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "获取", keys.Aggregate((a, b) => a + "," + b));
}
return null;
}
}

配置文件加了密码的设置

源码是柘木写的:

         /// <summary>
/// IP地址中可以加入auth验证 password@ip:port
/// </summary>
/// <param name="hosts"></param>
/// <returns></returns>
public static List<RedisEndpoint> ToRedisEndPoints(this IEnumerable<string> hosts)
{
if (hosts == null) return new List<RedisEndpoint>();
//redis终结点的列表
var redisEndpoints = new List<RedisEndpoint>();
foreach (var host in hosts)
{
RedisEndpoint endpoint;
string[] hostParts;
if (host.Contains("@"))
{
hostParts = host.SplitOnLast('@');
var password = hostParts[];
hostParts = hostParts[].Split(':');
endpoint = GetRedisEndPoint(hostParts);
endpoint.Password = password;
}
else
{
hostParts = host.Split(':');
endpoint = GetRedisEndPoint(hostParts);
}
redisEndpoints.Add(endpoint);
}
return redisEndpoints;
}

c# redis密码验证笔记的更多相关文章

  1. PHP操作Redis(一) PHP连接Redis,含Redis密码验证、指定某一Redis数据库

    台服务器上都快开启200个redis实例了,看着就崩溃了.这么做无非就是想让不同类型的数据属于不同的应用程序而彼此分开. 那么,redis有没有什么方法使不同的应用程序数据彼此分开同时又存储在相同的实 ...

  2. IdentityServer4 学习笔记[2]-用户名密码验证

    回顾 上一篇介绍了IdentityServer4客户端授权的方式,今天来看看IdentityServer4的基于密码验证的方式,与客户端验证相比,主要是配置文件调整一下,让我们来看一下 配置修改 pu ...

  3. Redis:学习笔记-04

    Redis:学习笔记-04 该部分内容,参考了 bilibili 上讲解 Redis 中,观看数最多的课程 Redis最新超详细版教程通俗易懂,来自 UP主 遇见狂神说 10. Redis主从复制 1 ...

  4. Redis入门学习笔记一

    Redis 简要描述: 1.  Redis 是啥 ? Redis 英文名称全称为: Remote Dictionary Server ,中译为远程字典服务器. 是一款区分于磁盘数据库如(Mysql)的 ...

  5. Nginx密码验证 ngx_http_auth_basic_module模块

    有时候我们需要限制某些目录只允许指定的用户才可以访问,我们可以给指定的目录添加一个用户限制. nginx给我们提供了ngx_http_auth_basic_module模块来实现这个功能. 模块ngx ...

  6. redis密码设置、访问权限控制等安全设置

    redis作为一个高速数据库,在互联网上,必须有对应的安全机制来进行保护,方法有2,如下. 1.比较安全的办法是采用绑定IP的方式来进行控制.  请在redis.conf文件找到如下配置 # If y ...

  7. Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十一)redis密码设置、安全设置

    警惕 前一篇文章<Spring+SpringMVC+MyBatis+easyUI整合进阶篇(九)Linux下安装redis及redis的常用命令和操作>主要是一个简单的介绍,针对redis ...

  8. Redis 密码设置和查看密码

    Redis 密码设置和查看密码 redis没有实现访问控制这个功能,但是它提供了一个轻量级的认证方式,可以编辑redis.conf配置来启用认证. 1.初始化Redis密码: 在配置文件中有个参数: ...

  9. Redis 密码设置和查看密码(二)

    Redis 密码设置和查看密码 redis没有实现访问控制这个功能,但是它提供了一个轻量级的认证方式,可以编辑redis.conf配置来启用认证. 1.初始化Redis密码: 在配置文件中有个参数: ...

随机推荐

  1. C语言和Python语言在存储变量方面的不同

    C语言和Python语言在存储变量方面的不同 众所周知,Python是脚本语言,边解释边执行,而C语言是编译型语言 存储变量: C语言定义变量,变量本身代表的就是大小,任何一个字母或者数字 符号均可以 ...

  2. 如何修改layer-layui中的confirm

    需求: 改成 背景: 这个confirm是layui中的layer弹出框,要想修改这个弹出框的内容岂不是要去修改源码?当我在源码里扒拉半天梳理好了逻辑之后,突然意识到,其实我本可以不必这么麻烦的,直接 ...

  3. 阶段5 3.微服务项目【学成在线】_day03 CMS页面管理开发_14-异常处理-异常处理的问题分析

    这块代码没有异常处理.如果在Service出现了异常代码,在哪里捕获?要么在Servive内捕获,要么在调用service的地方也就是controller内捕获 每个调用service的地方都要去捕获 ...

  4. logback 和 log4j对比,及相关配置

    Logback 一.logback的介绍 Logback是由log4j创始人设计的又一个开源日志组件.logback当前分成三个模块:logback-core,logback- classic和log ...

  5. windows7导入k8s用户证书

    通过浏览器访问 需要给浏览器生成一个 client 证书,访问 apiserver 的 6443 https 端口时使用 这里使用部署 kubectl 命令行工具时创建的 admin 证书.私钥和上面 ...

  6. 使用apache commons net进行ftp传输

    apache commons net的maven地址: http://mvnrepository.com/artifact/commons-net/commons-net/3.6 <!-- ht ...

  7. Ubuntu 18.04 上使用xrdp远程桌面连接

    参考:https://blog.csdn.net/qq_25556149/article/details/82216190 1,环境查看 2,安装 xrdp.tightvncserver apt-ge ...

  8. 【ARTS】01_24_左耳听风-201900422~2019004028

    ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...

  9. python列表插入--append(), extend(), insert()

    append(),extend(), insert()都是列表操作中常用的插入函数.其中前两个均接收一个参数,并插入到列表尾部.最后一个接收两个参数,将参数2插入到参数1之前. 本文主要讨论appen ...

  10. Docker跨主机网络实践

    Docker使用中网络管理是最麻烦的,在项目初始化前期就需要进行合理的规划,如果在比较理想的单主机的网络通信是比较简单的,但如果涉及到跨主机的网络就需要使用docker自带的overlay netwo ...