Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support redis master-slave and fragmented redis switching functions #65

Closed
cw2018 opened this issue Jun 21, 2020 · 5 comments · Fixed by #90
Closed

support redis master-slave and fragmented redis switching functions #65

cw2018 opened this issue Jun 21, 2020 · 5 comments · Fixed by #90
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@cw2018
Copy link

cw2018 commented Jun 21, 2020

使用场景:

在本地使用的单个Redis:
redisStub := redis.StdRedisConfig("myredis").Build()

在正式环境使用的是Redis集群:
redisStub := redis.StdRedisClusterConfig("myredis").Build()

这样就产生一个问题,在代码里使用Redis的地方都需要判断是本地环境还是线上正式环境。
在框架中是否可以进一步封装,对于使用者不用管是什么环境,只需要传一个参数来确定是否为Redis集群?或者有更好的方案?

@askuy
Copy link
Contributor

askuy commented Jun 21, 2020

使用场景:

在本地使用的单个Redis:
redisStub := redis.StdRedisConfig("myredis").Build()

在正式环境使用的是Redis集群:
redisStub := redis.StdRedisClusterConfig("myredis").Build()

这样就产生一个问题,在代码里使用Redis的地方都需要判断是本地环境还是线上正式环境。
在框架中是否可以进一步封装,对于使用者不用管是什么环境,只需要传一个参数来确定是否为Redis集群?或者有更好的方案?

这个可以规定,redis cluster和普通redis实现了一个redis interface。

然后你通过运行环境,在代码层面将不同的redis实例赋值给定义为interface的Redis Stub,如下所示

var RedisStub RedisInterface
if env =="prod" {
    RedisStub = redis.StdRedisClusterConfig("myredis").Build()
}else {
    RedisStub = redis.StdRedisConfig("myredis").Build()
}

type RedisInterface interface {
    Get()
    Set()
    ...
}

我们会看一下,普通redis和redis cluster的方法有没有统一起来。你也可以按我们方法,先自己试一下。

@cw2018
Copy link
Author

cw2018 commented Jun 21, 2020

ok

@gorexlv gorexlv changed the title [BUG]Redis集群环境和本地环境的小问题 统一Redis集群环境和单机环境配置 Jun 22, 2020
@gorexlv gorexlv added good first issue Good for newcomers enhancement New feature or request help wanted Extra attention is needed labels Jun 22, 2020
@OhBonsai
Copy link
Contributor

OhBonsai commented Jul 1, 2020

Hi, 有人认领了这个Issue, 如果没有 我想Pick~

@askuy
Copy link
Contributor

askuy commented Jul 1, 2020

Hi, 有人认领了这个Issue, 如果没有 我想Pick~
非常欢迎

@OhBonsai
Copy link
Contributor

OhBonsai commented Jul 3, 2020

@askuy PTAL

@zhangmingke zhangmingke changed the title 统一Redis集群环境和单机环境配置 support redis master-slave and fragmented redis switching functions Jul 6, 2020
@mlboy mlboy closed this as completed in #90 Jul 14, 2020
mlboy added a commit that referenced this issue Jul 14, 2020
unified stub and cluster configuration #65
achillesss pushed a commit to achillesss/jupiter that referenced this issue Oct 27, 2020
unified stub and cluster configuration douyu#65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants