From 1577bc9864f60589d826855d0b9a979bca712439 Mon Sep 17 00:00:00 2001 From: xmdhs Date: Thu, 12 Oct 2023 19:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20redis=20=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yaml | 4 +++- db/cache/redis_test.go | 38 ++++++++++++++++++++++++++++++++++++++ service/user_test.go | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 db/cache/redis_test.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index eec7ca3..100e4f4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,9 +24,11 @@ jobs: run: | bash build.sh - - name: start mysql + - name: start mysql / redis run: | sudo systemctl start mysql.service + apt update + apt install redis - name: Test run: go test -tags="redis,sqlite" -race -v ./... diff --git a/db/cache/redis_test.go b/db/cache/redis_test.go new file mode 100644 index 0000000..57d4ce6 --- /dev/null +++ b/db/cache/redis_test.go @@ -0,0 +1,38 @@ +//go:build redis + +package cache + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRedis(t *testing.T) { + c := NewRedis("127.0.0.1:6379", "") + + key := []byte("key") + value := []byte("value") + + require.Nil(t, c.Put(key, value, time.Now().Add(1*time.Hour))) + + v, err := c.Get(key) + require.Nil(t, err) + + assert.Equal(t, v, value) + + require.Nil(t, c.Del(key)) + + v, err = c.Get(key) + require.Nil(t, err) + require.Nil(t, v) + + require.Nil(t, c.Put(key, value, time.Now().Add(2*time.Second))) + time.Sleep(3 * time.Second) + + v, err = c.Get(key) + require.Nil(t, err) + require.Nil(t, v) +} diff --git a/service/user_test.go b/service/user_test.go index 08f2ce6..c9363d0 100644 --- a/service/user_test.go +++ b/service/user_test.go @@ -8,6 +8,7 @@ import ( "os" "testing" + _ "github.com/go-sql-driver/mysql" "github.com/samber/lo" "github.com/xmdhs/authlib-skin/config" "github.com/xmdhs/authlib-skin/db/cache"