weloe / token-go-extensions Goto Github PK
View Code? Open in Web Editor NEWhttps://github.com/weloe/token-go
License: Apache License 2.0
https://github.com/weloe/token-go
License: Apache License 2.0
【描述】
作者你好,这里在调用 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)
}
【描述】
作者你好,本仓库应用的 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
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.