From 55e6ac5d835d088ccd98bc8633eddcf5ae550322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 20 Apr 2025 18:05:01 +0800 Subject: [PATCH] =?UTF-8?q?RedisCmd=20=E5=A2=9E=E5=8A=A0=20MarshalBinary?= =?UTF-8?q?=20=E5=AE=9E=E7=8E=B0,=20redis=E5=BA=93=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E6=95=B0=E6=8D=AE=E6=97=B6,=20=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=AD=A4=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- redis.go | 4 ++++ redis_test.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/redis.go b/redis.go index 11ef9ce..3e78c85 100644 --- a/redis.go +++ b/redis.go @@ -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" diff --git a/redis_test.go b/redis_test.go index 1b91860..932321b 100644 --- a/redis_test.go +++ b/redis_test.go @@ -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"`) + }) }