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

v2.0.6 gdb缓存异常 #1755

Closed
qinyuguang opened this issue Apr 13, 2022 · 1 comment
Closed

v2.0.6 gdb缓存异常 #1755

qinyuguang opened this issue Apr 13, 2022 · 1 comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@qinyuguang
Copy link
Contributor

go 1.17
gf v2.0.6

设置gdb缓存后,实际上没有使用缓存
看tracing每次执行查询,都会做 查询缓存-查询DB-设置缓存

示例代码,查询5次

package main

import (
	"time"

	_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
	_ "github.com/lib/pq"

	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gcache"
	"github.com/gogf/gf/v2/os/gctx"
)

func main() {
	adapter := gcache.NewAdapterRedis(g.Redis())
	g.DB().GetCache().SetAdapter(adapter)

	ctx := gctx.New()

	for i := 0; i < 5; i++ {
		g.DB().Model("test").Ctx(ctx).Cache(gdb.CacheOption{
			Duration: time.Hour,
			Name:     "test",
		}).Where("id", 1).One()
	}
}

输出日志

2022-04-13 13:12:31.001 [DEBU] {e8402053b05ce51678242d0b8f355a9d} [ 26 ms] [default] [rows:1  ] SELECT * FROM "test" WHERE "id"=1 LIMIT 1 
2022-04-13 13:12:31.025 [DEBU] {e8402053b05ce51678242d0b8f355a9d} [ 21 ms] [default] [rows:1  ] SELECT * FROM "test" WHERE "id"=1 LIMIT 1 
2022-04-13 13:12:31.052 [DEBU] {e8402053b05ce51678242d0b8f355a9d} [ 21 ms] [default] [rows:1  ] SELECT * FROM "test" WHERE "id"=1 LIMIT 1 
2022-04-13 13:12:31.078 [DEBU] {e8402053b05ce51678242d0b8f355a9d} [ 24 ms] [default] [rows:1  ] SELECT * FROM "test" WHERE "id"=1 LIMIT 1 
2022-04-13 13:12:31.101 [DEBU] {e8402053b05ce51678242d0b8f355a9d} [ 19 ms] [default] [rows:1  ] SELECT * FROM "test" WHERE "id"=1 LIMIT 1 
@houseme
Copy link
Member

houseme commented Apr 13, 2022

2022-04-13 20:33:36.892 [DEBU] {5077cf67c274e5161877125fdbeb4e79} [ 77 ms] [default] [rows:16 ] SHOW FULL COLUMNS FROM `account_base` 
2022-04-13 20:33:36.955 [DEBU] {5077cf67c274e5161877125fdbeb4e79} [ 24 ms] [default] [rows:1  ] SELECT * FROM `account_base` WHERE `id`=1 LIMIT 1 
	adapter := gcache.NewAdapterRedis(g.Redis())
	g.DB().GetCache().SetAdapter(adapter)

	ctx := gctx.New()

	for i := 0; i < 5; i++ {
		g.DB().Model("account_base").Ctx(ctx).Cache(gdb.CacheOption{
			Duration: time.Hour,
			Name:     "test",
		}).Where("id", 1).One()
	}

redis 有配置吗?如:

redis:
  default:
    address: "192.168.100.2:6379"
    db: 7
    pass: "xxxx"

qinyuguang pushed a commit to qinyuguang/gf that referenced this issue Apr 13, 2022
gqcn added a commit that referenced this issue Apr 18, 2022
@gqcn gqcn added bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version. labels Apr 18, 2022
@gqcn gqcn closed this as completed Apr 18, 2022
houseme pushed a commit to houseme/gf that referenced this issue Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

3 participants