Comments (5)
使用场景:
在本地使用的单个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的方法有没有统一起来。你也可以按我们方法,先自己试一下。
from jupiter.
ok
from jupiter.
Hi, 有人认领了这个Issue, 如果没有 我想Pick~
from jupiter.
Hi, 有人认领了这个Issue, 如果没有 我想Pick~
非常欢迎
from jupiter.
@askuy PTAL
from jupiter.
Related Issues (20)
- feat: refactor jupiter new like gonew HOT 1
- 一些关于官网文档的小意见
- Go install toolkit ERROR? How to fix it? HOT 2
- feat: support sentinel for server and client HOT 1
- Bug:panic of variable "span" rocketmq PushConsumer when EnableTrace is not set. HOT 1
- feat: support convert protobuf enum to error HOT 1
- feat: support clickhouse client HOT 1
- release: v0.9.11 HOT 1
- feat: support table store client HOT 1
- feat: support auto complete for rocketmq addr config
- "Unable to locate build via Github Actions API" for the public repository HOT 3
- feat(cmd): support generate echo route based on protobuf HOT 1
- feat: all client Intruction support Must(Build/Singleton) API based on lo.Must. HOT 1
- feat: support release protoc-gen-go-echo/gin/xerror HOT 1
- opti: RestrictParallel execution optimization HOT 1
- config.toml不知道怎么用
- create方法传入slice报Error: reflect: call of reflect.Value.Interface on zero Value HOT 4
- feat: use docker instead of request httpbin directly HOT 1
- feat: log support change level dynamically HOT 7
- where is deployment/docker-compose.yml ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jupiter.