Comments (1)
今天测试了一个您的这个cache,对于主键查询的,应该是OK的了。思路不错。
小小的建议一下,cache包,可以出个New,其返回是*gorm.DB,如下所示
func New(c *Conf) (db *gorm.DB, err error) {
gormCfg := &gorm.Config{}
dsn := c.DB.Dsn
switch strings.ToLower(c.DB.Type) {
// supported: MySQL, PostgreSQL, SQLite, SQL Server TiDB
case "mysql", "mariadb":
db, err = gorm.Open(mysql.Open(dsn), gormCfg)
case "postgre", "postgres", "postgresql":
db, err = gorm.Open(postgres.Open(dsn), gormCfg)
case "sqlite":
db, err = gorm.Open(sqlite.Open(dsn), gormCfg)
case "sqlserver":
db, err = gorm.Open(sqlserver.Open(dsn), gormCfg)
default:
err = errors.New("gormredis - NewWithRedis: unsupported db type found: " + c.DB.Type)
return nil, err
}
rds := Store.New(c.Redis)
gormPlugin := &cache{
Store: rds,
prefix: c.RedisPrefix,
Serializer: &DefaultSerializer{},
}
err = db.Use(gormPlugin)
if err != nil {
return nil, err
}
return db, nil
}
这样,就可以作为一个可以直接new之后就使用的包了,而不是需要再在调用程序里面处理一堆。
如果您觉得这个方案可以的话,我提个pr。
from gorm-cache.
Related Issues (4)
- 一点点建议 HOT 2
- 缓存key有问题 HOT 2
- Redis 支持 V9
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 gorm-cache.