From 627b8d214dae879cad21d8a30c90783cf399a40e Mon Sep 17 00:00:00 2001 From: guzeng Date: Wed, 16 Feb 2022 10:50:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0exists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exists.go | 23 +++++++++++++++++++++++ exists_test.go | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 exists.go create mode 100644 exists_test.go diff --git a/exists.go b/exists.go new file mode 100644 index 0000000..1ab1681 --- /dev/null +++ b/exists.go @@ -0,0 +1,23 @@ +package redis + +import ( + redisdb "github.com/gomodule/redigo/redis" +) + +//exists +func Exists(key string) (bool, error) { + c := pool.Get() + defer c.Close() + + return redisdb.Bool(c.Do("EXISTS", key)) + +} + +//hexists +func HExists(key string) (bool, error) { + c := pool.Get() + defer c.Close() + + return redisdb.Bool(c.Do("HEXISTS", key)) + +} diff --git a/exists_test.go b/exists_test.go new file mode 100644 index 0000000..4141461 --- /dev/null +++ b/exists_test.go @@ -0,0 +1,18 @@ +package redis + +import ( + // "strconv" + "testing" + // "tgo/helper" +) + +func Test_Exists(t *testing.T) { + + ret3, err := Exists("testing23") + t.Log(ret3) + t.Log(err) + + ret3, err := HExists("testing23") + t.Log(ret3) + t.Log(err) +}