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

gdb cache with redis be broken at binary->[]byte #2790

Open
WankkoRee opened this issue Jul 21, 2023 · 1 comment
Open

gdb cache with redis be broken at binary->[]byte #2790

WankkoRee opened this issue Jul 21, 2023 · 1 comment
Labels
enhancement help wanted planned This issue/proposal is planned into our next steps.

Comments

@WankkoRee
Copy link
Contributor

1. What version of Go and system type/arch are you using?

go version go1.20.5 windows/amd64

2. What version of GoFrame are you using?

v2.5.0

3. Can this issue be re-produced with the latest release?

yes

4. What did you do?

database:
  default:
    link:  "mysql:root:123456@tcp(127.0.0.1:3306)/test"

redis:
  default:
    address: 127.0.0.1:6379
    db: 2
package main

import (
	_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
	_ "github.com/gogf/gf/contrib/nosql/redis/v2"
	"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"
	"github.com/gogf/gf/v2/os/glog"
)

type Test struct {
	Id   int
	Test []byte
}

func main() {
	ctx := gctx.New()
	g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(g.Redis()))
	if err := g.Redis().FlushDB(ctx); err != nil { // clear cache
		return
	}

	var test []*Test

	glog.Print(ctx, "----无缓存----")
	test = []*Test{}
	if err := g.DB().Model("test").
		Cache(gdb.CacheOption{
			Duration: 0,
			Name:     "test",
			Force:    false,
		}).
		Scan(&test); err != nil {
		glog.Error(ctx, err)
		return
	}
	for _, t := range test {
		glog.Printf(ctx, "%+v", t)
	}

	glog.Print(ctx, "----有缓存----")
	test = []*Test{}
	if err := g.DB().Model("test").
		Cache(gdb.CacheOption{
			Duration: 0,
			Name:     "test",
			Force:    false,
		}).
		Scan(&test); err != nil {
		glog.Error(ctx, err)
		return
	}
	for _, t := range test {
		glog.Printf(ctx, "%+v", t)
	}
}
CREATE TABLE `test`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `test` binary(3) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of test
-- ----------------------------
INSERT INTO `test` VALUES (1, 0x000000);
INSERT INTO `test` VALUES (2, 0x111111);
INSERT INTO `test` VALUES (3, 0x222222);

5. What did you expect to see?

2023-07-21 09:48:52.471 {6c3de3dfdabe7317b3f6fc2c6b610101} ----无缓存----
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:1 Test:[0 0 0]}
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:2 Test:[17 17 17]}
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:3 Test:[34 34 34]}
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} ----有缓存----
2023-07-21 09:48:52.496 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:1 Test:[0 0 0]}
2023-07-21 09:48:52.497 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:2 Test:[17 17 17]}
2023-07-21 09:48:52.497 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:3 Test:[34 34 34]}

6. What did you see instead?

2023-07-21 09:48:52.471 {6c3de3dfdabe7317b3f6fc2c6b610101} ----无缓存----
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:1 Test:[0 0 0]}
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:2 Test:[17 17 17]}
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:3 Test:[34 34 34]}
2023-07-21 09:48:52.493 {6c3de3dfdabe7317b3f6fc2c6b610101} ----有缓存----
2023-07-21 09:48:52.496 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:1 Test:[65 65 65 65]}
2023-07-21 09:48:52.497 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:2 Test:[69 82 69 82]}
2023-07-21 09:48:52.497 {6c3de3dfdabe7317b3f6fc2c6b610101} &{Id:3 Test:[73 105 73 105]}
@gqcn gqcn added enhancement help wanted planned This issue/proposal is planned into our next steps. labels Sep 25, 2023
@github-actions
Copy link

Hello @WankkoRee. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!
你好 @WankkoRee。我们喜欢您的提案/反馈,并希望您或其他社区成员通过拉取请求做出贡献。我们提前感谢您的贡献,并期待对其进行审查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted planned This issue/proposal is planned into our next steps.
Projects
None yet
Development

No branches or pull requests

2 participants