参考博客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. Oracle impdp导入数据报错:无法读取要读取的存储文件(Linux)

    当向Linux下的Oracle11g通过数据泵impdp导入数据库时,出现如图所示错误. 错误原因:bdck.dmp该为大写. 切记:Linux系统严格区分大小写.

  2. fastjson序列化和反序列化报com.alibaba.fastjson.JSONException: autoType is not support异常问题,解决方案整合

    1.问题起因 2017年3月15日,fastjson官方发布安全升级公告,该公告介绍fastjson在1.2.24及之前的版本存在代码执行漏洞,当恶意攻击者提交一个精心构造的序列化数据到服务端时,由于 ...

  3. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_13-webpack研究-webpack入门程序

    创建webpack测试的目录 定义webpack的入口文件 mdel01必须导出,main里面才能导入 导出多个 数组的写法 main是入口文件,里面已经引入了vue.min和model01.js   ...

  4. ZSDR017

    *---------------------------------------------------------------------- *ZSDR017-客户订货价格和库存 *-------- ...

  5. React Native运行安卓报错解决记录

    1>Error:Configuration with name ‘default’ not found. 解决链接: http://blog.csdn.net/u011240877/articl ...

  6. 去除表视图section的粘性问题

    //  去除section的粘性 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView == self.tabl ...

  7. souce and bash 的区别

    对于一些环境变量的配置文件,如想使更改后立即生效,多用 souce +file 执行后即可.如/etc/profile 里加了配置, source 和  bash 的区别: source filena ...

  8. tushare获取股票每日重要的基本面指标数据,并存入Elasticsearch

    tushare是一个开放的,免费的金融数据平台,包含沪深股票数据,指数数据,基金数据,期货数据,期权数据,债券数据,外汇数据,港股数据,行业经济数据,宏观经济数据以及新闻快讯等特色数据.其中以沪深股票 ...

  9. 最新 盛趣游戏java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.盛趣游戏等10家互联网公司的校招Offer,因为某些自身原因最终选择了盛趣游戏.6.7月主要是做系统复习.项目复盘.Leet ...

  10. JavaSE基础(十一)--Java数组

    Java 数组 数组对于每一门编程语言来说都是重要的数据结构之一,当然不同语言对数组的实现及处理也不尽相同. Java 语言中提供的数组是用来存储固定大小的同类型元素. 数组特点: 其长度是确定的.数 ...