1.设置访问密码
config set requirepass 123456
2.连接redis服务器
private static string redisHost = ConfigHelper.GetAppSetting("redisHost"); private static int redisPort = ConfigHelper.GetAppSetting("redisPort").AsInt32(); private static string redisPass = ConfigHelper.GetAppSetting("redisPass"); private static RedisClient redis = new RedisClient(redisHost, redisPort, redisPass);
可能遇到的问题:
1.如果报如下错误:
DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode
可能就是因为没有设置访问密码
2.如果无法连接redis服务器,可能是因为端口的问题:
/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
如果都设置好了还报错,稍等一会即可
3.NOAUTH Authentication required.
auth 123456:重新设置访问密码即可
![](https://images2015.cnblogs.com/blog/455634/201704/455634-20170425141057787-563726188.png)
![](https://images2015.cnblogs.com/blog/455634/201704/455634-20170425141108522-2008634892.png)
![](https://images2015.cnblogs.com/blog/455634/201704/455634-20170425141118944-448383234.png)
![](https://images2015.cnblogs.com/blog/455634/201704/455634-20170425141131709-351385811.png)