mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
CI update; Example update for package gcache
This commit is contained in:
33
.github/workflows/gf.yml
vendored
33
.github/workflows/gf.yml
vendored
@ -58,17 +58,42 @@ jobs:
|
||||
|
||||
- name: Before Script
|
||||
run: |
|
||||
date
|
||||
find . -name "*.go" | xargs gofmt -w
|
||||
git diff --name-only --exit-code || if [ $? != 0 ];then echo "Notice: gofmt check failed,please gofmt before pr." && exit 1; fi
|
||||
git diff --name-only --exit-code || if [ $? != 0 ]; then echo "Notice: gofmt check failed,please gofmt before pr." && exit 1; fi
|
||||
echo "gofmt check pass."
|
||||
sudo echo "127.0.0.1 local" | sudo tee -a /etc/hosts
|
||||
|
||||
- name: CLI Build & Test
|
||||
run: |
|
||||
cd cmd/gf
|
||||
go mod tidy
|
||||
go build ./...
|
||||
go test ./...
|
||||
|
||||
- name: Example Build & Test
|
||||
run: |
|
||||
cd example
|
||||
go mod tidy
|
||||
go build ./...
|
||||
go test ./...
|
||||
|
||||
- name: Contrib Build & Test
|
||||
run: |
|
||||
cd contrib
|
||||
for file in `find . -name go.mod`; do
|
||||
cd ${file%/*}
|
||||
go mod tidy
|
||||
go build ./...
|
||||
go test ./...
|
||||
done
|
||||
|
||||
- name: Run i386 Arch Test
|
||||
run: GOARCH=386 go test -v ./... || exit 1
|
||||
run: |
|
||||
GOARCH=386 go test -v ./... || exit 1
|
||||
|
||||
- name: Run amd64 Arch Test
|
||||
run: GOARCH=amd64 go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic
|
||||
run: |
|
||||
GOARCH=amd64 go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic
|
||||
|
||||
- name: Report Coverage
|
||||
uses: codecov/codecov-action@v2
|
||||
|
||||
@ -50,9 +50,6 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
|
||||
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
|
||||
@ -60,13 +57,10 @@ github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
|
||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||
github.com/mattn/go-sqlite3 v1.14.10 h1:MLn+5bFRlWMGoSRmJour3CL1w/qL96mvipqpwQW/Sfk=
|
||||
github.com/mattn/go-sqlite3 v1.14.10/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
@ -82,8 +76,6 @@ github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
|
||||
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
@ -157,9 +149,8 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
|
||||
@ -21,10 +21,6 @@ github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
|
||||
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
|
||||
@ -38,9 +34,7 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
@ -197,7 +191,6 @@ go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJre
|
||||
go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
|
||||
go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY=
|
||||
go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
@ -315,10 +308,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/grpc v1.43.0 h1:Eeu7bZtDZ2DpRCsLhUlcrLnvYaMK1Gz86a+hMVvELmM=
|
||||
google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
|
||||
@ -74,6 +74,24 @@ func (r *Redis) Do(ctx context.Context, command string, args ...interface{}) (*g
|
||||
return conn.Do(ctx, command, args...)
|
||||
}
|
||||
|
||||
// MustConn performs as function Conn, but it panics if any error occurs internally.
|
||||
func (r *Redis) MustConn(ctx context.Context) *RedisConn {
|
||||
c, err := r.Conn(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// MustDo performs as function Do, but it panics if any error occurs internally.
|
||||
func (r *Redis) MustDo(ctx context.Context, command string, args ...interface{}) *gvar.Var {
|
||||
v, err := r.Do(ctx, command, args...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Close closes current redis client, closes its connection pool and releases all its related resources.
|
||||
func (r *Redis) Close(ctx context.Context) error {
|
||||
if r == nil {
|
||||
|
||||
@ -45,7 +45,7 @@ var (
|
||||
//
|
||||
// The parameter `pointer` can be type of: *struct/**struct/*[]struct/*[]*struct.
|
||||
//
|
||||
// It supports single and multiple struct convertion:
|
||||
// It supports single and multiple struct converting:
|
||||
// 1. Single struct, post content like: {"id":1, "name":"john"} or ?id=1&name=john
|
||||
// 2. Multiple struct, post content like: [{"id":1, "name":"john"}, {"id":, "name":"smith"}]
|
||||
//
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gcache_test
|
||||
|
||||
import (
|
||||
@ -5,12 +11,13 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
func ExampleNew() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly.
|
||||
c := gcache.New()
|
||||
@ -45,7 +52,6 @@ func ExampleNew() {
|
||||
}
|
||||
|
||||
func ExampleCache_Set() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -61,7 +67,6 @@ func ExampleCache_Set() {
|
||||
}
|
||||
|
||||
func ExampleCache_SetIfNotExist() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -96,7 +101,6 @@ func ExampleCache_SetIfNotExist() {
|
||||
}
|
||||
|
||||
func ExampleCache_SetMap() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -124,7 +128,6 @@ func ExampleCache_SetMap() {
|
||||
}
|
||||
|
||||
func ExampleCache_Size() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -143,7 +146,6 @@ func ExampleCache_Size() {
|
||||
}
|
||||
|
||||
func ExampleCache_Update() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -188,7 +190,6 @@ func ExampleCache_Update() {
|
||||
}
|
||||
|
||||
func ExampleCache_UpdateExpire() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -210,7 +211,6 @@ func ExampleCache_UpdateExpire() {
|
||||
}
|
||||
|
||||
func ExampleCache_Values() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -229,7 +229,6 @@ func ExampleCache_Values() {
|
||||
}
|
||||
|
||||
func ExampleCache_Close() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -249,11 +248,9 @@ func ExampleCache_Close() {
|
||||
// Output:
|
||||
// v
|
||||
// v
|
||||
|
||||
}
|
||||
|
||||
func ExampleCache_Contains() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -273,11 +270,9 @@ func ExampleCache_Contains() {
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
|
||||
}
|
||||
|
||||
func ExampleCache_Data() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -298,7 +293,6 @@ func ExampleCache_Data() {
|
||||
}
|
||||
|
||||
func ExampleCache_Get() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -316,7 +310,6 @@ func ExampleCache_Get() {
|
||||
}
|
||||
|
||||
func ExampleCache_GetExpire() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -334,7 +327,6 @@ func ExampleCache_GetExpire() {
|
||||
}
|
||||
|
||||
func ExampleCache_GetOrSet() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -354,7 +346,6 @@ func ExampleCache_GetOrSet() {
|
||||
}
|
||||
|
||||
func ExampleCache_GetOrSetFunc() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -379,7 +370,6 @@ func ExampleCache_GetOrSetFunc() {
|
||||
}
|
||||
|
||||
func ExampleCache_GetOrSetFuncLock() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -406,7 +396,6 @@ func ExampleCache_GetOrSetFuncLock() {
|
||||
}
|
||||
|
||||
func ExampleCache_Keys() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -419,7 +408,6 @@ func ExampleCache_Keys() {
|
||||
|
||||
// Output:
|
||||
// [k1]
|
||||
|
||||
}
|
||||
|
||||
func ExampleCache_KeyStrings() {
|
||||
@ -436,7 +424,6 @@ func ExampleCache_KeyStrings() {
|
||||
}
|
||||
|
||||
func ExampleCache_Remove() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -457,7 +444,6 @@ func ExampleCache_Remove() {
|
||||
}
|
||||
|
||||
func ExampleCache_Removes() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -500,11 +486,9 @@ func ExampleCache_MustGet() {
|
||||
|
||||
// Output:
|
||||
// v1
|
||||
|
||||
}
|
||||
|
||||
func ExampleCache_MustGetOrSet() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -519,11 +503,9 @@ func ExampleCache_MustGetOrSet() {
|
||||
// Output:
|
||||
// v1
|
||||
// v1
|
||||
|
||||
}
|
||||
|
||||
func ExampleCache_MustGetOrSetFunc() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -547,7 +529,6 @@ func ExampleCache_MustGetOrSetFunc() {
|
||||
}
|
||||
|
||||
func ExampleCache_MustGetOrSetFuncLock() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -580,7 +561,7 @@ func ExampleCache_MustContains() {
|
||||
// Set Cache
|
||||
c.Set(ctx, "k", "v", 0)
|
||||
|
||||
// Contains returns true if `key` exists in the cache, or else returns false.
|
||||
// MustContains returns true if `key` exists in the cache, or else returns false.
|
||||
// return true
|
||||
data := c.MustContains(ctx, "k")
|
||||
fmt.Println(data)
|
||||
@ -592,11 +573,9 @@ func ExampleCache_MustContains() {
|
||||
// Output:
|
||||
// true
|
||||
// false
|
||||
|
||||
}
|
||||
|
||||
func ExampleCache_MustGetExpire() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -613,7 +592,6 @@ func ExampleCache_MustGetExpire() {
|
||||
}
|
||||
|
||||
func ExampleCache_MustSize() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -632,7 +610,6 @@ func ExampleCache_MustSize() {
|
||||
}
|
||||
|
||||
func ExampleCache_MustData() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -647,7 +624,6 @@ func ExampleCache_MustData() {
|
||||
}
|
||||
|
||||
func ExampleCache_MustKeys() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -678,7 +654,6 @@ func ExampleCache_MustKeyStrings() {
|
||||
}
|
||||
|
||||
func ExampleCache_MustValues() {
|
||||
|
||||
// Create a cache object,
|
||||
// Of course, you can also easily use the gcache package method directly
|
||||
c := gcache.New()
|
||||
@ -686,10 +661,81 @@ func ExampleCache_MustValues() {
|
||||
// Write value
|
||||
c.Set(ctx, "k1", "v1", 0)
|
||||
|
||||
// Values returns all values in the cache as slice.
|
||||
// MustValues returns all values in the cache as slice.
|
||||
data := c.MustValues(ctx)
|
||||
fmt.Println(data)
|
||||
|
||||
// Output:
|
||||
// [v1]
|
||||
}
|
||||
|
||||
func ExampleCache_SetAdapter() {
|
||||
var (
|
||||
err error
|
||||
ctx = gctx.New()
|
||||
cache = gcache.New()
|
||||
redisConfig = &gredis.Config{
|
||||
Address: "127.0.0.1:6379",
|
||||
Db: 9,
|
||||
}
|
||||
cacheKey = `key`
|
||||
cacheValue = `value`
|
||||
)
|
||||
// Create redis client object.
|
||||
redis, err := gredis.New(redisConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Create redis cache adapter and set it to cache object.
|
||||
cache.SetAdapter(gcache.NewAdapterRedis(redis))
|
||||
|
||||
// Set and Get using cache object.
|
||||
err = cache.Set(ctx, cacheKey, cacheValue, time.Second)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(cache.MustGet(ctx, cacheKey).String())
|
||||
|
||||
// Get using redis client.
|
||||
fmt.Println(redis.MustDo(ctx, "GET", cacheKey).String())
|
||||
|
||||
// Output:
|
||||
// value
|
||||
// value
|
||||
}
|
||||
|
||||
func ExampleCache_GetAdapter() {
|
||||
var (
|
||||
err error
|
||||
ctx = gctx.New()
|
||||
cache = gcache.New()
|
||||
redisConfig = &gredis.Config{
|
||||
Address: "127.0.0.1:6379",
|
||||
Db: 10,
|
||||
}
|
||||
cacheKey = `key`
|
||||
cacheValue = `value`
|
||||
)
|
||||
redis, err := gredis.New(redisConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cache.SetAdapter(gcache.NewAdapterRedis(redis))
|
||||
|
||||
// Set and Get using cache object.
|
||||
err = cache.Set(ctx, cacheKey, cacheValue, time.Second)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(cache.MustGet(ctx, cacheKey).String())
|
||||
|
||||
// Get using redis client.
|
||||
v, err := cache.GetAdapter().(*gcache.AdapterRedis).Get(ctx, cacheKey)
|
||||
fmt.Println(err)
|
||||
fmt.Println(v.String())
|
||||
|
||||
// Output:
|
||||
// value
|
||||
// <nil>
|
||||
// value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user