From 23e8dacdeb20bc0053d59e529ec320de96807055 Mon Sep 17 00:00:00 2001 From: comin2013 <350878418@qq.com> Date: Thu, 22 Apr 2021 18:53:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0struct=202=20hash=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sysmodule/redismodule/redismodule_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sysmodule/redismodule/redismodule_test.go b/sysmodule/redismodule/redismodule_test.go index 8676f29..fcea7b2 100644 --- a/sysmodule/redismodule/redismodule_test.go +++ b/sysmodule/redismodule/redismodule_test.go @@ -24,13 +24,29 @@ func Test_Example(t *testing.T) { module.SetString(1000,2*1000) module.SetStringExpire("key2","value2","60") - //支持直接存储struct数据 + //支持直接存储struct数据(json string) jsonData := struct{ A string B string }{"Aaaa","Bbbb"} module.SetStringJSON("key3",&jsonData) + // struct 2 redis hash + a := struct{ + A string `redis:"a"` + B int `redis:"b"` + }{ + "ccc", + 1, + } + module.HSetStruct("skey", &a) + a.A = "xx" + module.HGetStruct("skey", &a) + if a.A == "xx"{ + fmt.Println("struct 2 hash failed.") + } + + //支持存储map数据结构,map中的key与value与redis的key,value对象 mapData := map[interface{}]interface{}{} mapData["key4"] = "value4"