RedisCmd 增加 MarshalBinary 实现, redis库序列化数据时, 演示实现此方法

This commit is contained in:
zhangdeman committed 2025-04-20 18:05:01 +08:00
1 parent 3aba815bac
commit 55e6ac5d83
2 files changed
+9

No files matched your search

+4
View File
@@ -17,6 +17,10 @@ func (rc RedisCmd) MarshalJSON() ([]byte, error) {
return []byte(`"` + rc.String() + `"`), nil
}
func (rc RedisCmd) MarshalBinary() ([]byte, error) {
return rc.MarshalJSON()
}
const (
RedisCommandExists RedisCmd = "EXISTS"
RedisCommandTTL RedisCmd = "TTL"
+5
View File
@@ -30,4 +30,9 @@ func TestRedisCmd_String(t *testing.T) {
So(err, ShouldBeNil)
So(string(jsonData), ShouldEqual, `["SET"]`)
})
Convey("redis cmd MarshalBinary", t, func() {
str, err := RedisCommandSet.MarshalBinary()
So(err, ShouldBeNil)
So(string(str), ShouldEqual, `"SET"`)
})
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.