英文:
Trying to Connect Redis JSON
问题
我正在尝试在Go中使用Redis JSON。
我正在使用go-redis进行Redis连接,并使用go-rejson进行JSON处理。
package RedisModule
import (
"context"
"fmt"
goredis "github.com/go-redis/redis/v8"
"github.com/nitishm/go-rejson"
)
var ctx = context.Background()
var Rdb goredis.Client
func ConfigureRedis() goredis.Client {
rdb := goredis.NewClient(&goredis.Options{
Addr: "localhost:6379",
Password: "", // 没有设置密码
DB: 0, // 使用默认的DB
})
Rdb = *rdb
rh := rejson.NewReJSONHandler()
rh.SetGoRedisClient(rdb)
return *rdb
}
我遇到了一个错误cannot use rdb (variable of type *redis.Client) as *redis.Client value in argument to rh.SetGoRedisClient compiler(IncompatibleAssign)
。
我参考了https://github.com/nitishm/go-rejson。
英文:
I am trying to use Redis JSON in Go.
I am using go-redis for redis connection and go-rejson for JSON Handler
package RedisModule
import (
"context"
"fmt"
goredis "github.com/go-redis/redis/v8"
"github.com/nitishm/go-rejson"
)
var ctx = context.Background()
var Rdb goredis.Client
func ConfigureRedis() goredis.Client {
rdb := goredis.NewClient(&goredis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
Rdb = *rdb
rh := rejson.NewReJSONHandler()
rh.SetGoRedisClient(rdb)
return *rdb
}
I am getting an error cannot use rdb (variable of type *redis.Client) as *redis.Client value in argument to rh.SetGoRedisClient compiler(IncompatibleAssign)
.
I was referring https://github.com/nitishm/go-rejson
答案1
得分: 1
将"github.com/nitishm/go-rejson"
更改为rejson "github.com/nitishm/go-rejson/v4"
。它会起作用。
英文:
Note from OP, originally included as an edit to the question:
Change "github.com/nitishm/go-rejson"
to rejson "github.com/nitishm/go-rejson/v4"
</br> It will work
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论