Giter VIP home page Giter VIP logo

token-go-extensions's People

Contributors

weloe avatar

Stargazers

 avatar

Watchers

 avatar

token-go-extensions's Issues

【bug】redis-adapter use go-redis v8 get state error

【描述】
作者你好,这里在调用 QrCodeEnforcer.GetQRCodeState(qrCodeId) 函数时,内部代码提示以下错误

2024/06/18 16:53:35 Adapter.Get() failed: unable to convert string to []byte

【问题定位】
往 GetQRCodeState 函数内部走到 redis-adapter 时

func (r *RedisAdapter) Get(key string, t ...reflect.Type) interface{} {
	value, err := r.client.Get(context.Background(), key).Result()
	if err != nil {
		return nil
	}
        ...
        // !!问题点:这里不太对,上面 go-redis v8 响应的就是一个 string 类型,这么再一次 util.InterfaceToBytes 转换就会出现异常
	bytes, err := util.InterfaceToBytes(value)
	if err != nil {
		log.Printf("Adapter.Get() failed: %v", err)
		return nil
	}
	instance := reflect.New(t[0].Elem()).Interface()
	err = r.serializer.UnSerialize(bytes, instance)
	...
}

util.InterfaceToBytes 定义

func InterfaceToBytes(data interface{}) ([]byte, error) {
	if b, ok := data.([]byte); ok {
		return b, nil
	}
	return nil, fmt.Errorf("unable to convert %T to []byte", data)
}

【Feat】upgrade token-go module version v0.1.2 -> v0.1.8

【描述】
作者你好,本仓库应用的 token-go-extensions/redis-adapter/token-go 版本能升级下吗?

token-go version v0.1.2 -> v0.1.8

可能涉及到的改动( need review )

1,补充实现 GetCountsFilteredKey 方法
cluster_adapter.go

func (r *ClusterAdapter) GetCountsFilteredKey(filterKeyPrefix string) (int, error) {
	keys, err := r.client.Keys(context.Background(), filterKeyPrefix).Result()
	if err != nil {
		return 0, err
	}
	return len(keys), nil
}

ring_adapter.go

func (r *RingAdapter) GetCountsFilteredKey(filterKeyPrefix string) (int, error) {
	keys, err := r.client.Keys(context.Background(), filterKeyPrefix).Result()
	if err != nil {
		return 0, err
	}
	return len(keys), nil
}

sentinel_adapter.go

func (r *SentinelAdapter) GetCountsFilteredKey(filterKeyPrefix string) (int, error) {
	keys, err := r.client.Keys(context.Background(), filterKeyPrefix).Result()
	if err != nil {
		return 0, err
	}
	return len(keys), nil
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.