version v2.3.0 (#2392)

* v2.3.0

* up

* up

* up
This commit is contained in:
John Guo 2023-01-11 19:19:41 +08:00 committed by GitHub
parent 5e72b03b0a
commit 6ff4ed84e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 511 additions and 260 deletions

View File

@ -20,6 +20,7 @@ type cFix struct {
type cFixInput struct {
g.Meta `name:"fix"`
Path string `name:"path" brief:"directory path, it uses current working directory in default"`
}
type cFixOutput struct{}
@ -32,12 +33,15 @@ type cFixItem struct {
func (c cFix) Index(ctx context.Context, in cFixInput) (out *cFixOutput, err error) {
mlog.Print(`start auto fixing...`)
defer mlog.Print(`done!`)
err = c.doFix()
if in.Path == "" {
in.Path = gfile.Pwd()
}
err = c.doFix(in)
return
}
func (c cFix) doFix() (err error) {
version, err := c.getVersion()
func (c cFix) doFix(in cFixInput) (err error) {
version, err := c.getVersion(in)
if err != nil {
mlog.Fatal(err)
}
@ -83,10 +87,10 @@ func (c cFix) doFixV23(version string) error {
return gfile.ReplaceDirFunc(replaceFunc, ".", "*.go", true)
}
func (c cFix) getVersion() (string, error) {
func (c cFix) getVersion(in cFixInput) (string, error) {
var (
err error
path = "go.mod"
path = gfile.Join(in.Path, "go.mod")
version string
)
if !gfile.Exists(path) {
@ -95,7 +99,7 @@ func (c cFix) getVersion() (string, error) {
err = gfile.ReadLines(path, func(line string) error {
array := gstr.SplitAndTrim(line, " ")
if len(array) > 0 {
if array[0] == gfPackage {
if gstr.HasPrefix(array[0], gfPackage) {
version = array[1]
}
}

View File

@ -21,7 +21,7 @@ type cUp struct {
}
const (
gfPackage = `github.com/gogf/gf/v2`
gfPackage = `github.com/gogf/gf/`
cUpEg = `
gf up
gf up -a
@ -46,20 +46,19 @@ type cUpInput struct {
type cUpOutput struct{}
func (c cUp) Index(ctx context.Context, in cUpInput) (out *cUpOutput, err error) {
defer mlog.Print(`done!`)
defer func() {
if err == nil {
mlog.Print(`done!`)
}
}()
if in.All {
in.Cli = true
in.Fix = true
}
if err = c.doUpgradeVersion(ctx); err != nil {
if err = c.doUpgradeVersion(ctx, in); err != nil {
return nil, err
}
if in.Fix {
if err = c.doAutoFixing(ctx); err != nil {
return nil, err
}
}
//if in.Cli {
// if err = c.doUpgradeCLI(ctx); err != nil {
// return nil, err
@ -68,9 +67,14 @@ func (c cUp) Index(ctx context.Context, in cUpInput) (out *cUpOutput, err error)
return
}
func (c cUp) doUpgradeVersion(ctx context.Context) (err error) {
func (c cUp) doUpgradeVersion(ctx context.Context, in cUpInput) (err error) {
mlog.Print(`start upgrading version...`)
type Package struct {
Name string
Version string
}
var (
dir = gfile.Pwd()
temp string
@ -78,12 +82,15 @@ func (c cUp) doUpgradeVersion(ctx context.Context) (err error) {
)
for {
if gfile.Exists(path) {
var packages []string
var packages []Package
err = gfile.ReadLines(path, func(line string) error {
line = gstr.Trim(line)
if gstr.HasPrefix(line, gfPackage) {
pkg := gstr.Explode(" ", line)[0]
packages = append(packages, pkg)
array := gstr.SplitAndTrim(line, " ")
packages = append(packages, Package{
Name: array[0],
Version: array[1],
})
}
return nil
})
@ -91,11 +98,18 @@ func (c cUp) doUpgradeVersion(ctx context.Context) (err error) {
return
}
for _, pkg := range packages {
mlog.Printf(`upgrading %s`, pkg)
command := fmt.Sprintf(`go get -u %s@latest`, pkg)
mlog.Printf(`upgrading "%s" from "%s" to "latest"`, pkg.Name, pkg.Version)
command := fmt.Sprintf(`go get -u %s@latest`, pkg.Name)
if err = gproc.ShellRun(ctx, command); err != nil {
return
}
mlog.Print()
}
if in.Fix {
if err = c.doAutoFixing(ctx, dir); err != nil {
return err
}
mlog.Print()
}
return
}
@ -110,12 +124,13 @@ func (c cUp) doUpgradeVersion(ctx context.Context) (err error) {
func (c cUp) doUpgradeCLI(ctx context.Context) (err error) {
mlog.Print(`start upgrading cli...`)
return
}
func (c cUp) doAutoFixing(ctx context.Context) (err error) {
mlog.Print(`start auto fixing...`)
err = cFix{}.doFix()
func (c cUp) doAutoFixing(ctx context.Context, dirPath string) (err error) {
mlog.Printf(`auto fixing path "%s"...`, dirPath)
err = cFix{}.doFix(cFixInput{
Path: dirPath,
})
return
}

View File

@ -69,7 +69,10 @@ func main() {
if err != nil {
panic(err)
}
command.Run(ctx)
err = command.RunWithError(ctx)
if err != nil {
panic(err)
}
}
// zsh alias "git fetch" conflicts checks.

131
container/gvar/gvar_vars.go Normal file
View File

@ -0,0 +1,131 @@
// 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 gvar
import (
"github.com/gogf/gf/v2/util/gconv"
)
// Vars is a slice of *Var.
type Vars []*Var
// Strings converts and returns `vs` as []string.
func (vs Vars) Strings() (s []string) {
for _, v := range vs {
s = append(s, v.String())
}
return s
}
// Interfaces converts and returns `vs` as []interface{}.
func (vs Vars) Interfaces() (s []interface{}) {
for _, v := range vs {
s = append(s, v.Val())
}
return s
}
// Float32s converts and returns `vs` as []float32.
func (vs Vars) Float32s() (s []float32) {
for _, v := range vs {
s = append(s, v.Float32())
}
return s
}
// Float64s converts and returns `vs` as []float64.
func (vs Vars) Float64s() (s []float64) {
for _, v := range vs {
s = append(s, v.Float64())
}
return s
}
// Ints converts and returns `vs` as []Int.
func (vs Vars) Ints() (s []int) {
for _, v := range vs {
s = append(s, v.Int())
}
return s
}
// Int8s converts and returns `vs` as []int8.
func (vs Vars) Int8s() (s []int8) {
for _, v := range vs {
s = append(s, v.Int8())
}
return s
}
// Int16s converts and returns `vs` as []int16.
func (vs Vars) Int16s() (s []int16) {
for _, v := range vs {
s = append(s, v.Int16())
}
return s
}
// Int32s converts and returns `vs` as []int32.
func (vs Vars) Int32s() (s []int32) {
for _, v := range vs {
s = append(s, v.Int32())
}
return s
}
// Int64s converts and returns `vs` as []int64.
func (vs Vars) Int64s() (s []int64) {
for _, v := range vs {
s = append(s, v.Int64())
}
return s
}
// Uints converts and returns `vs` as []uint.
func (vs Vars) Uints() (s []uint) {
for _, v := range vs {
s = append(s, v.Uint())
}
return s
}
// Uint8s converts and returns `vs` as []uint8.
func (vs Vars) Uint8s() (s []uint8) {
for _, v := range vs {
s = append(s, v.Uint8())
}
return s
}
// Uint16s converts and returns `vs` as []uint16.
func (vs Vars) Uint16s() (s []uint16) {
for _, v := range vs {
s = append(s, v.Uint16())
}
return s
}
// Uint32s converts and returns `vs` as []uint32.
func (vs Vars) Uint32s() (s []uint32) {
for _, v := range vs {
s = append(s, v.Uint32())
}
return s
}
// Uint64s converts and returns `vs` as []uint64.
func (vs Vars) Uint64s() (s []uint64) {
for _, v := range vs {
s = append(s, v.Uint64())
}
return s
}
// Scan converts `vs` to []struct/[]*struct.
func (vs Vars) Scan(pointer interface{}, mapping ...map[string]string) error {
return gconv.Structs(vs.Interfaces(), pointer, mapping...)
}

View File

@ -0,0 +1,60 @@
// 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 gvar_test
import (
"testing"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/test/gtest"
)
func TestVars(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var vs = gvar.Vars{
gvar.New(1),
gvar.New(2),
gvar.New(3),
}
t.AssertEQ(vs.Strings(), []string{"1", "2", "3"})
t.AssertEQ(vs.Interfaces(), []interface{}{1, 2, 3})
t.AssertEQ(vs.Float32s(), []float32{1, 2, 3})
t.AssertEQ(vs.Float64s(), []float64{1, 2, 3})
t.AssertEQ(vs.Ints(), []int{1, 2, 3})
t.AssertEQ(vs.Int8s(), []int8{1, 2, 3})
t.AssertEQ(vs.Int16s(), []int16{1, 2, 3})
t.AssertEQ(vs.Int32s(), []int32{1, 2, 3})
t.AssertEQ(vs.Int64s(), []int64{1, 2, 3})
t.AssertEQ(vs.Uints(), []uint{1, 2, 3})
t.AssertEQ(vs.Uint8s(), []uint8{1, 2, 3})
t.AssertEQ(vs.Uint16s(), []uint16{1, 2, 3})
t.AssertEQ(vs.Uint32s(), []uint32{1, 2, 3})
t.AssertEQ(vs.Uint64s(), []uint64{1, 2, 3})
})
}
func TestVars_Scan(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
type User struct {
Id int
Name string
}
var vs = gvar.Vars{
gvar.New(g.Map{"id": 1, "name": "john"}),
gvar.New(g.Map{"id": 2, "name": "smith"}),
}
var users []User
err := vs.Scan(&users)
t.AssertNil(err)
t.Assert(len(users), 2)
t.Assert(users[0].Id, 1)
t.Assert(users[0].Name, "john")
t.Assert(users[1].Id, 2)
t.Assert(users[1].Name, "smith")
})
}

View File

@ -162,7 +162,7 @@ func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]inte
// will return a list of nil values.
//
// https://redis.io/commands/hmget/
func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) ([]*gvar.Var, error) {
func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "HMGet", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
return v.Vars(), err
}
@ -178,7 +178,7 @@ func (r GroupHash) HKeys(ctx context.Context, key string) ([]string, error) {
// HVals return all values in the hash stored at key.
//
// https://redis.io/commands/hvals/
func (r GroupHash) HVals(ctx context.Context, key string) ([]*gvar.Var, error) {
func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "HVals", key)
return v.Vars(), err
}
@ -188,7 +188,7 @@ func (r GroupHash) HVals(ctx context.Context, key string) ([]*gvar.Var, error) {
// so the length of the reply is twice the size of the hash.
//
// https://redis.io/commands/hgetall/
func (r GroupHash) HGetAll(ctx context.Context, key string) (map[string]*gvar.Var, error) {
func (r GroupHash) HGetAll(ctx context.Context, key string) (*gvar.Var, error) {
v, err := r.redis.Do(ctx, "HGetAll", key)
return v.MapStrVar(), err
return v, err
}

View File

@ -195,7 +195,7 @@ func (r GroupList) LSet(ctx context.Context, key string, index int64, value inte
// For example, -1 is the last element of the list, -2 the penultimate, and so on.
//
// https://redis.io/commands/lrange/
func (r GroupList) LRange(ctx context.Context, key string, start, stop int64) ([]*gvar.Var, error) {
func (r GroupList) LRange(ctx context.Context, key string, start, stop int64) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "LRange", key, start, stop)
return v.Vars(), err
}
@ -220,7 +220,7 @@ func (r GroupList) LTrim(ctx context.Context, key string, start, stop int64) err
// block. A timeout of zero can be used to block indefinitely.
//
// https://redis.io/commands/blpop/
func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) ([]*gvar.Var, error) {
func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "BLPop", append(gconv.Interfaces(keys), timeout)...)
return v.Vars(), err
}
@ -234,7 +234,7 @@ func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) ([]
// block. A timeout of zero can be used to block indefinitely.
//
// https://redis.io/commands/brpop/
func (r GroupList) BRPop(ctx context.Context, timeout int64, keys ...string) ([]*gvar.Var, error) {
func (r GroupList) BRPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "BRPop", append(gconv.Interfaces(keys), timeout)...)
return v.Vars(), err
}

View File

@ -151,7 +151,7 @@ func (r GroupSet) SCard(ctx context.Context, key string) (int64, error) {
// It returns all elements of the set.
//
// https://redis.io/commands/smembers/
func (r GroupSet) SMembers(ctx context.Context, key string) ([]*gvar.Var, error) {
func (r GroupSet) SMembers(ctx context.Context, key string) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "SMembers", key)
return v.Vars(), err
}
@ -176,7 +176,7 @@ func (r GroupSet) SMIsMember(ctx context.Context, key, member interface{}, membe
// It returns list with members of the resulting set.
//
// https://redis.io/commands/sinter/
func (r GroupSet) SInter(ctx context.Context, key string, keys ...string) ([]*gvar.Var, error) {
func (r GroupSet) SInter(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
var s = []interface{}{key}
s = append(s, gconv.Interfaces(keys)...)
v, err := r.redis.Do(ctx, "SInter", s...)
@ -203,7 +203,7 @@ func (r GroupSet) SInterStore(ctx context.Context, destination string, key strin
// It returns list with members of the resulting set.
//
// https://redis.io/commands/sunion/
func (r GroupSet) SUnion(ctx context.Context, key string, keys ...string) ([]*gvar.Var, error) {
func (r GroupSet) SUnion(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
var s = []interface{}{key}
s = append(s, gconv.Interfaces(keys)...)
v, err := r.redis.Do(ctx, "SUnion", s...)
@ -230,7 +230,7 @@ func (r GroupSet) SUnionStore(ctx context.Context, destination, key string, keys
// It returns list with members of the resulting set.
//
// https://redis.io/commands/sdiff/
func (r GroupSet) SDiff(ctx context.Context, key string, keys ...string) ([]*gvar.Var, error) {
func (r GroupSet) SDiff(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
var s = []interface{}{key}
s = append(s, gconv.Interfaces(keys)...)
v, err := r.redis.Do(ctx, "SDiff", s...)

View File

@ -119,7 +119,7 @@ func (r GroupSortedSet) ZCount(ctx context.Context, key string, min, max string)
// order.
//
// https://redis.io/commands/zrange/
func (r GroupSortedSet) ZRange(ctx context.Context, key string, start, stop int64, option ...gredis.ZRangeOption) ([]*gvar.Var, error) {
func (r GroupSortedSet) ZRange(ctx context.Context, key string, start, stop int64, option ...gredis.ZRangeOption) (gvar.Vars, error) {
var usedOption interface{}
if len(option) > 0 {
usedOption = option[0]

View File

@ -1,186 +0,0 @@
// 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 redis_test
import (
"context"
"fmt"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gutil"
)
func Example_autoMarshalUnmarshalMap() {
var (
err error
result *gvar.Var
ctx = context.Background()
key = "user"
data = g.Map{
"id": 10000,
"name": "john",
}
)
_, err = g.Redis().Do(ctx, "SET", key, data)
if err != nil {
panic(err)
}
result, err = g.Redis().Do(ctx, "GET", key)
if err != nil {
panic(err)
}
fmt.Println(result.Map())
}
func Example_autoMarshalUnmarshalStruct() {
type User struct {
Id int
Name string
}
var (
err error
result *gvar.Var
ctx = context.Background()
key = "user"
user = &User{
Id: 10000,
Name: "john",
}
)
_, err = g.Redis().Do(ctx, "SET", key, user)
if err != nil {
panic(err)
}
result, err = g.Redis().Do(ctx, "GET", key)
if err != nil {
panic(err)
}
var user2 *User
if err = result.Struct(&user2); err != nil {
panic(err)
}
fmt.Println(user2.Id, user2.Name)
}
func Example_autoMarshalUnmarshalStructSlice() {
type User struct {
Id int
Name string
}
var (
err error
result *gvar.Var
ctx = context.Background()
key = "user-slice"
users1 = []User{
{
Id: 1,
Name: "john1",
},
{
Id: 2,
Name: "john2",
},
}
)
_, err = g.Redis().Do(ctx, "SET", key, users1)
if err != nil {
panic(err)
}
result, err = g.Redis().Do(ctx, "GET", key)
if err != nil {
panic(err)
}
var users2 []User
if err = result.Structs(&users2); err != nil {
panic(err)
}
fmt.Println(users2)
}
func Example_hSet() {
var (
err error
result *gvar.Var
ctx = context.Background()
key = "user"
)
_, err = g.Redis().Do(ctx, "HSET", key, "id", 10000)
if err != nil {
panic(err)
}
_, err = g.Redis().Do(ctx, "HSET", key, "name", "john")
if err != nil {
panic(err)
}
result, err = g.Redis().Do(ctx, "HGETALL", key)
if err != nil {
panic(err)
}
fmt.Println(result.Map())
// May Output:
// map[id:10000 name:john]
}
func Example_hMSet_Map() {
var (
ctx = context.Background()
key = "user_100"
data = g.Map{
"name": "gf",
"sex": 0,
"score": 100,
}
)
_, err := g.Redis().Do(ctx, "HMSET", append(g.Slice{key}, gutil.MapToSlice(data)...)...)
if err != nil {
g.Log().Fatal(ctx, err)
}
v, err := g.Redis().Do(ctx, "HMGET", key, "name")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(v.Slice())
// May Output:
// [gf]
}
func Example_hMSet_Struct() {
type User struct {
Name string `json:"name"`
Sex int `json:"sex"`
Score int `json:"score"`
}
var (
ctx = context.Background()
key = "user_100"
data = &User{
Name: "gf",
Sex: 0,
Score: 100,
}
)
_, err := g.Redis().Do(ctx, "HMSET", append(g.Slice{key}, gutil.StructToSlice(data)...)...)
if err != nil {
g.Log().Fatal(ctx, err)
}
v, err := g.Redis().Do(ctx, "HMGET", key, "name")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(v.Slice())
// May Output:
// ["gf"]
}

View File

@ -7,8 +7,9 @@
package redis_test
import (
"github.com/gogf/gf/v2/test/gtest"
"testing"
"github.com/gogf/gf/v2/test/gtest"
)
func Test_GroupHash_HSet(t *testing.T) {
@ -329,6 +330,6 @@ func Test_GroupHash_HGetAll(t *testing.T) {
t.AssertNil(err)
r1, err := redis.HGetAll(ctx, key)
t.Assert(r1, fields)
t.Assert(r1.Map(), fields)
})
}

View File

@ -22,8 +22,9 @@ import (
)
func main() {
r := zookeeper.New([]string{"127.0.0.1:2181"}, zookeeper.WithRootPath("/gogf"))
gsvc.SetRegistry(r)
gsvc.SetRegistry(zookeeper.New(
[]string{"127.0.0.1:2181"}, zookeeper.WithRootPath("/gogf"),
))
s := g.Server(`hello.svc`)
s.BindHandler("/", func(r *ghttp.Request) {
@ -49,7 +50,9 @@ import (
)
func main() {
gsvc.SetRegistry(zookeeper.New([]string{"127.0.0.1:2181"},zookeeper.WithRootPath("/gogf")))
gsvc.SetRegistry(zookeeper.New(
[]string{"127.0.0.1:2181"}, zookeeper.WithRootPath("/gogf"),
))
gsel.SetBuilder(gsel.NewBuilderRoundRobin())
client := g.Client()

View File

@ -41,7 +41,7 @@ type ConfigNode struct {
Charset string `json:"charset"` // (Optional, "utf8mb4" in default) Custom charset when operating on database.
Protocol string `json:"protocol"` // (Optional, "tcp" in default) See net.Dial for more information which networks are available.
Timezone string `json:"timezone"` // (Optional) Sets the time zone for displaying and interpreting time stamps.
Namespace string `json:"namespace"` // Namespace for some databases. Eg, in pgsql, the `Name` acts as the `catalog`, the `NameSpace` acts as the `schema`.
Namespace string `json:"namespace"` // (Optional) Namespace for some databases. Eg, in pgsql, the `Name` acts as the `catalog`, the `NameSpace` acts as the `schema`.
MaxIdleConnCount int `json:"maxIdle"` // (Optional) Max idle connection configuration for underlying connection pool.
MaxOpenConnCount int `json:"maxOpen"` // (Optional) Max open connection configuration for underlying connection pool.
MaxConnLifeTime time.Duration `json:"maxLifeTime"` // (Optional) Max amount of time a connection may be idle before being closed.

View File

@ -25,8 +25,8 @@ type IGroupHash interface {
HIncrBy(ctx context.Context, key, field string, increment int64) (int64, error)
HIncrByFloat(ctx context.Context, key, field string, increment float64) (float64, error)
HMSet(ctx context.Context, key string, fields map[string]interface{}) error
HMGet(ctx context.Context, key string, fields ...string) ([]*gvar.Var, error)
HMGet(ctx context.Context, key string, fields ...string) (gvar.Vars, error)
HKeys(ctx context.Context, key string) ([]string, error)
HVals(ctx context.Context, key string) ([]*gvar.Var, error)
HGetAll(ctx context.Context, key string) (map[string]*gvar.Var, error)
HVals(ctx context.Context, key string) (gvar.Vars, error)
HGetAll(ctx context.Context, key string) (*gvar.Var, error)
}

View File

@ -26,10 +26,10 @@ type IGroupList interface {
LIndex(ctx context.Context, key string, index int64) (*gvar.Var, error)
LInsert(ctx context.Context, key string, op LInsertOp, pivot, value interface{}) (int64, error)
LSet(ctx context.Context, key string, index int64, value interface{}) (*gvar.Var, error)
LRange(ctx context.Context, key string, start, stop int64) ([]*gvar.Var, error)
LRange(ctx context.Context, key string, start, stop int64) (gvar.Vars, error)
LTrim(ctx context.Context, key string, start, stop int64) error
BLPop(ctx context.Context, timeout int64, keys ...string) ([]*gvar.Var, error)
BRPop(ctx context.Context, timeout int64, keys ...string) ([]*gvar.Var, error)
BLPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error)
BRPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error)
RPopLPush(ctx context.Context, source, destination string) (*gvar.Var, error)
BRPopLPush(ctx context.Context, source, destination string, timeout int64) (*gvar.Var, error)
}

View File

@ -22,12 +22,12 @@ type IGroupSet interface {
SRem(ctx context.Context, key string, member interface{}, members ...interface{}) (int64, error)
SMove(ctx context.Context, source, destination string, member interface{}) (int64, error)
SCard(ctx context.Context, key string) (int64, error)
SMembers(ctx context.Context, key string) ([]*gvar.Var, error)
SMembers(ctx context.Context, key string) (gvar.Vars, error)
SMIsMember(ctx context.Context, key, member interface{}, members ...interface{}) ([]int, error)
SInter(ctx context.Context, key string, keys ...string) ([]*gvar.Var, error)
SInter(ctx context.Context, key string, keys ...string) (gvar.Vars, error)
SInterStore(ctx context.Context, destination string, key string, keys ...string) (int64, error)
SUnion(ctx context.Context, key string, keys ...string) ([]*gvar.Var, error)
SUnion(ctx context.Context, key string, keys ...string) (gvar.Vars, error)
SUnionStore(ctx context.Context, destination, key string, keys ...string) (int64, error)
SDiff(ctx context.Context, key string, keys ...string) ([]*gvar.Var, error)
SDiff(ctx context.Context, key string, keys ...string) (gvar.Vars, error)
SDiffStore(ctx context.Context, destination string, key string, keys ...string) (int64, error)
}

View File

@ -20,7 +20,7 @@ type IGroupSortedSet interface {
ZIncrBy(ctx context.Context, key string, increment float64, member interface{}) (float64, error)
ZCard(ctx context.Context, key string) (int64, error)
ZCount(ctx context.Context, key string, min, max string) (int64, error)
ZRange(ctx context.Context, key string, start, stop int64, option ...ZRangeOption) ([]*gvar.Var, error)
ZRange(ctx context.Context, key string, start, stop int64, option ...ZRangeOption) (gvar.Vars, error)
ZRevRange(ctx context.Context, key string, start, stop int64, option ...ZRevRangeOption) (*gvar.Var, error)
ZRank(ctx context.Context, key string, member interface{}) (int64, error)
ZRevRank(ctx context.Context, key string, member interface{}) (int64, error)

View File

@ -5,10 +5,11 @@ go 1.15
require (
github.com/gogf/gf/contrib/config/apollo/v2 v2.0.0
github.com/gogf/gf/contrib/config/kubecm/v2 v2.0.0
github.com/gogf/gf/contrib/config/nacos/v2 v2.0.0-00010101000000-000000000000
github.com/gogf/gf/contrib/config/nacos/v2 v2.2.6
github.com/gogf/gf/contrib/config/polaris/v2 v2.0.0
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.2.1
github.com/gogf/gf/contrib/registry/etcd/v2 v2.1.0-rc3.0.20220523034830-510fa3faf03f
github.com/gogf/gf/contrib/nosql/redis/v2 v2.2.6
github.com/gogf/gf/contrib/registry/etcd/v2 v2.2.6
github.com/gogf/gf/contrib/registry/polaris/v2 v2.0.0
github.com/gogf/gf/contrib/trace/jaeger/v2 v2.0.0
github.com/gogf/gf/v2 v2.2.1
@ -27,6 +28,7 @@ replace (
github.com/gogf/gf/contrib/config/nacos/v2 => ../contrib/config/nacos/
github.com/gogf/gf/contrib/config/polaris/v2 => ../contrib/config/polaris/
github.com/gogf/gf/contrib/drivers/mysql/v2 => ../contrib/drivers/mysql/
github.com/gogf/gf/contrib/nosql/redis/v2 => ../contrib/nosql/redis/
github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/
github.com/gogf/gf/contrib/registry/polaris/v2 => ../contrib/registry/polaris/
github.com/gogf/gf/contrib/trace/jaeger/v2 => ../contrib/trace/jaeger/

View File

@ -124,6 +124,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
@ -179,6 +181,8 @@ github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@ -406,14 +410,17 @@ github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6Yf
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=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/ginkgo/v2 v2.1.4/go.mod h1:um6tUpWM/cxCK3/FK8BXqEiUMUwRgSM4JXG47RKZmLU=
github.com/onsi/ginkgo/v2 v2.1.6 h1:Fx2POJZfKRQcM1pH49qSZiYeu319wji004qX+GDovrU=
@ -421,6 +428,7 @@ github.com/onsi/ginkgo/v2 v2.1.6/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
@ -1011,6 +1019,7 @@ gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
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=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -0,0 +1,4 @@
redis:
default:
address: 127.0.0.1:6379
db: 1

View File

@ -0,0 +1,23 @@
package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
var ctx = gctx.New()
_, err := g.Redis().Set(ctx, "key", "value")
if err != nil {
g.Log().Fatal(ctx, err)
}
value, err := g.Redis().Get(ctx, "key")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.String())
}

View File

@ -0,0 +1,34 @@
package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/database/gredis"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
var (
config = gredis.Config{
Address: "127.0.0.1:6379",
Db: 1,
}
group = "cache"
ctx = gctx.New()
)
func main() {
gredis.SetConfig(&config, group)
_, err := g.Redis(group).Set(ctx, "key", "value")
if err != nil {
g.Log().Fatal(ctx, err)
}
value, err := g.Redis(group).Get(ctx, "key")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.String())
}

View File

@ -0,0 +1,4 @@
redis:
default:
address: 127.0.0.1:6379
db: 1

View File

@ -0,0 +1,34 @@
package main
import (
"fmt"
"time"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
var ctx = gctx.New()
err := g.Redis().SetEX(ctx, "key", "value", 1)
if err != nil {
g.Log().Fatal(ctx, err)
}
value, err := g.Redis().Get(ctx, "key")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.IsNil())
fmt.Println(value.String())
time.Sleep(time.Second)
value, err = g.Redis().Get(ctx, "key")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.IsNil())
fmt.Println(value.Val())
}

View File

@ -0,0 +1,4 @@
redis:
default:
address: 127.0.0.1:6379
db: 1

View File

@ -0,0 +1,30 @@
package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
var (
ctx = gctx.New()
channel = "channel"
)
conn, _ := g.Redis().Conn(ctx)
defer conn.Close(ctx)
_, err := conn.Subscribe(ctx, channel)
if err != nil {
g.Log().Fatal(ctx, err)
}
for {
msg, err := conn.ReceiveMessage(ctx)
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(msg.Payload)
}
}

View File

@ -0,0 +1,4 @@
redis:
default:
address: 127.0.0.1:6379
db: 1

View File

@ -0,0 +1,44 @@
package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
var (
ctx = gctx.New()
key = "key"
)
_, err := g.Redis().HSet(ctx, key, g.Map{
"id": 1,
"name": "john",
"score": 100,
})
if err != nil {
g.Log().Fatal(ctx, err)
}
// retrieve hash map
value, err := g.Redis().HGetAll(ctx, key)
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.Map())
// scan to struct
type User struct {
Id uint64
Name string
Score float64
}
var user *User
if err = value.Scan(&user); err != nil {
g.Log().Fatal(ctx, err)
}
g.Dump(user)
}

View File

@ -0,0 +1,4 @@
redis:
default:
address: 127.0.0.1:6379
db: 1

View File

@ -0,0 +1,23 @@
package main
import (
"fmt"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
var ctx = gctx.New()
_, err := g.Redis().Set(ctx, "key", "value")
if err != nil {
g.Log().Fatal(ctx, err)
}
value, err := g.Redis().Get(ctx, "key")
if err != nil {
g.Log().Fatal(ctx, err)
}
fmt.Println(value.String())
}

View File

@ -56,11 +56,7 @@ func (s *StorageRedisHashTable) Data(ctx context.Context, sessionId string) (dat
if err != nil {
return nil, err
}
data = make(map[string]interface{})
for k, v := range m {
data[k] = v.Val()
}
return
return m.Map(), nil
}
// GetSize retrieves the size of key-value pairs from storage.

View File

@ -171,7 +171,7 @@ func Fields(in FieldsInput) ([]Field, error) {
// The parameter `recursive` specifies the whether retrieving the fields recursively if the attribute
// is an embedded struct.
//
// Note that it only retrieves the exported attributes with first letter up-case from struct.
// Note that it only retrieves the exported attributes with first letter upper-case from struct.
func FieldMap(in FieldMapInput) (map[string]Field, error) {
fields, err := getFieldValues(in.Pointer)
if err != nil {

View File

@ -74,7 +74,7 @@ func ParseTag(tag string) map[string]string {
// The parameter `pointer` should be type of struct/*struct.
//
// Note that,
// 1. It only retrieves the exported attributes with first letter up-case from struct.
// 1. It only retrieves the exported attributes with first letter upper-case from struct.
// 2. The parameter `priority` should be given, it only retrieves fields that has given tag.
func TagFields(pointer interface{}, priority []string) ([]Field, error) {
return getFieldValuesByTagPriority(pointer, priority, map[string]struct{}{})
@ -85,7 +85,7 @@ func TagFields(pointer interface{}, priority []string) ([]Field, error) {
// The parameter `pointer` should be type of struct/*struct.
//
// Note that,
// 1. It only retrieves the exported attributes with first letter up-case from struct.
// 1. It only retrieves the exported attributes with first letter upper-case from struct.
// 2. The parameter `priority` should be given, it only retrieves fields that has given tag.
// 3. If one field has no specified tag, it uses its field name as result map key.
func TagMapName(pointer interface{}, priority []string) (map[string]string, error) {
@ -104,7 +104,7 @@ func TagMapName(pointer interface{}, priority []string) (map[string]string, erro
// The parameter `object` should be either type of struct/*struct/[]struct/[]*struct.
//
// Note that,
// 1. It only retrieves the exported attributes with first letter up-case from struct.
// 1. It only retrieves the exported attributes with first letter upper-case from struct.
// 2. The parameter `priority` should be given, it only retrieves fields that has given tag.
// 3. If one field has no specified tag, it uses its field name as result map key.
func TagMapField(object interface{}, priority []string) (map[string]Field, error) {

View File

@ -47,6 +47,11 @@ func SetTimeZone(zone string) (err error) {
}
}()
// It is already set to time.Local.
if strings.EqualFold(zone, time.Local.String()) {
return
}
// Load zone info from specified name.
location, err := time.LoadLocation(zone)
if err != nil {

View File

@ -38,7 +38,7 @@ func Test_Slice(t *testing.T) {
t.AssertEQ(gconv.SliceAny(" [26, 27] "), []interface{}{26, 27})
})
gtest.C(t, func(t *gtest.T) {
s := []*gvar.Var{
s := gvar.Vars{
gvar.New(1),
gvar.New(2),
}
@ -78,7 +78,7 @@ func Test_Slice_Int32s(t *testing.T) {
t.AssertEQ(gconv.Int32s([]float64{1, 2}), []int32{1, 2})
t.AssertEQ(gconv.Int32s([][]byte{[]byte{byte(1)}, []byte{byte(2)}}), []int32{1, 2})
s := []*gvar.Var{
s := gvar.Vars{
gvar.New(1),
gvar.New(2),
}
@ -107,7 +107,7 @@ func Test_Slice_Int64s(t *testing.T) {
t.AssertEQ(gconv.Int64s([]float64{1, 2}), []int64{1, 2})
t.AssertEQ(gconv.Int64s([][]byte{[]byte{byte(1)}, []byte{byte(2)}}), []int64{1, 2})
s := []*gvar.Var{
s := gvar.Vars{
gvar.New(1),
gvar.New(2),
}
@ -137,7 +137,7 @@ func Test_Slice_Uints(t *testing.T) {
t.AssertEQ(gconv.Uints([]float64{1, 2}), []uint{1, 2})
t.AssertEQ(gconv.Uints([][]byte{[]byte{byte(1)}, []byte{byte(2)}}), []uint{1, 2})
s := []*gvar.Var{
s := gvar.Vars{
gvar.New(1),
gvar.New(2),
}
@ -167,7 +167,7 @@ func Test_Slice_Uint32s(t *testing.T) {
t.AssertEQ(gconv.Uint32s([]float64{1, 2}), []uint32{1, 2})
t.AssertEQ(gconv.Uint32s([][]byte{[]byte{byte(1)}, []byte{byte(2)}}), []uint32{1, 2})
s := []*gvar.Var{
s := gvar.Vars{
gvar.New(1),
gvar.New(2),
}
@ -197,7 +197,7 @@ func Test_Slice_Uint64s(t *testing.T) {
t.AssertEQ(gconv.Uint64s([]float64{1, 2}), []uint64{1, 2})
t.AssertEQ(gconv.Uint64s([][]byte{[]byte{byte(1)}, []byte{byte(2)}}), []uint64{1, 2})
s := []*gvar.Var{
s := gvar.Vars{
gvar.New(1),
gvar.New(2),
}
@ -224,7 +224,7 @@ func Test_Slice_Float32s(t *testing.T) {
t.AssertEQ(gconv.Float32s([]float32{123}), []float32{123})
t.AssertEQ(gconv.Float32s([]float64{123}), []float32{123})
s := []*gvar.Var{
s := gvar.Vars{
gvar.New(1.1),
gvar.New(2.1),
}

View File

@ -2,5 +2,5 @@ package gf
const (
// VERSION is the current GoFrame version.
VERSION = "v2.2.6"
VERSION = "v2.3.0"
)