2881099 / csredis

.NET Core or .NET Framework 4.0+ client for Redis and Redis Sentinel (2.8) and Cluster. Includes both synchronous and asynchronous clients.
MIT License
2k stars 414 forks source link

哨兵模式,sentinel有密码,redis也有密码,应该如何连接? #342

Closed momo314 closed 3 years ago

momo314 commented 3 years ago
new CSRedisClient(conn, sentinels)

在conn种可以设置redis密码,如果sentinel没有密码,经测试,是可用的;但是如果sentinel也有密码的话,应该如何设置,并没有找到对应的文档,麻烦大神帮忙看下

jdnt commented 3 years ago

假设redis和sentinel密码相同,都是123456

var csredis = new CSRedis.CSRedisClient("homeworld,password=123456,defaultDatabase=0,poolsize=5,ssl=false,prefix=Home:", new[] { "192.168.245.25:26379", "192.168.245.30:26379", "192.168.245.60:26379" }); RedisHelper.Initialization(csredis); 或者放配置文件 json "Redis": { "Configuration": "homeworld,password=123456,defaultDatabase=0,poolsize=5,ssl=false,prefix=Home:", "Sentinels": [ "192.168.245.25:26379", "192.168.245.30:26379", "192.168.245.60:26379" ] } code var redisConfiguration = configuration.GetSection("Redis").Get<RedisConfigs>(); var csredis = new CSRedis.CSRedisClient(redisConfiguration.Configuration, redisConfiguration.Sentinels); RedisHelper.Initialization(csredis);

2881099 commented 3 years ago

关键 sentinel 设不了密码。

127.0.0.1:21479> auth 123 (error) ERR unknown command 'auth'

cherubic commented 3 years ago

关键 sentinel 设不了密码。

127.0.0.1:21479> auth 123 (error) ERR unknown command 'auth'

如果使用kubernetes helm来创建的redis sentinel的,是可以设置密码的。 相关文档如下:https://artifacthub.io/packages/helm/bitnami/redis#using-password-file

2881099 commented 3 years ago

如果确定可以的话,需要改源码。我正在重新新的 redis 客户端组件,本地搭建的哨兵无法执行 auth 命令。

新项目:https://github.com/2881099/FreeRedis

预计3-5个月可以使用。

cherubic commented 3 years ago

如果确定可以的话,需要改源码。我正在重新新的 redis 客户端组件,本地搭建的哨兵无法执行 auth 命令。

新项目:https://github.com/2881099/FreeRedis

预计3-5个月可以使用。

确定是可以的,不能使用命令来配置,应该是在搭建sentinel的时候使用conf文件来配置密码。 可以参考以下答案来配置密码:

https://stackoverflow.com/questions/46302125/redis-sentinel-authentication

2881099 commented 3 years ago

https://github.com/2881099/FreeRedis

好的,这个哨兵密码可以用了。目前完成度,同步方法的、集群、哨兵、主从、单机、管道、事务,都已经完成,并且通过测试。

异步后面想好了再做。如果对异步不纠结可以尝试引用源码试试。