From 299edfcc9a69e5e62408dcf67ec9a75276415065 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 13:40:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DRedisCommand=20BUG=20+=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 12 +++++++++++- go.sum | 8 ++++++++ redis.go | 2 +- redis_test.go | 29 +++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 go.sum create mode 100644 redis_test.go diff --git a/go.mod b/go.mod index dd35fa5..84b9078 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,13 @@ module git.zhangdeman.cn/zhangdeman/consts -go 1.19 +go 1.23.0 + +toolchain go1.24.2 + +require github.com/smartystreets/goconvey v1.8.1 + +require ( + github.com/gopherjs/gopherjs v1.17.2 // indirect + github.com/jtolds/gls v4.20.0+incompatible // indirect + github.com/smarty/assertions v1.15.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7fea79b --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= +github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY= +github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= +github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= +github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= diff --git a/redis.go b/redis.go index dedf955..0bd8a46 100644 --- a/redis.go +++ b/redis.go @@ -17,7 +17,7 @@ func (rc *RedisCmd) MarshalJSON() ([]byte, error) { return []byte(rc.String()), nil } -const ( +var ( RedisCommandExists RedisCmd = "EXISTS" RedisCommandTTL RedisCmd = "TTL" RedisCommandSet RedisCmd = "SET" diff --git a/redis_test.go b/redis_test.go new file mode 100644 index 0000000..f9900b8 --- /dev/null +++ b/redis_test.go @@ -0,0 +1,29 @@ +// Package consts ... +// +// Description : consts ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-04-20 13:29 +package consts + +import ( + "encoding/json" + . "github.com/smartystreets/goconvey/convey" + "testing" +) + +// RedisCmd_String 序列换 RedisCmd +func TestRedisCmd_String(t *testing.T) { + Convey("redis cmd字符串值", t, func() { + byteData, err := json.Marshal(RedisCommandSet) + So(err, ShouldBeNil) + So(RedisCommandSet.String(), ShouldEqual, "SET") + So(string(byteData), ShouldEqual, `"SET"`) + }) + Convey("redis cmd MarshalJSON", t, func() { + str, err := RedisCommandSet.MarshalJSON() + So(err, ShouldBeNil) + So(string(str), ShouldEqual, `SET`) + }) +}