尝试连接 Redis JSON。

huangapple go评论101阅读模式
英文:

Trying to Connect Redis JSON

问题

我正在尝试在Go中使用Redis JSON。
我正在使用go-redis进行Redis连接,并使用go-rejson进行JSON处理。

  1. package RedisModule
  2. import (
  3. "context"
  4. "fmt"
  5. goredis "github.com/go-redis/redis/v8"
  6. "github.com/nitishm/go-rejson"
  7. )
  8. var ctx = context.Background()
  9. var Rdb goredis.Client
  10. func ConfigureRedis() goredis.Client {
  11. rdb := goredis.NewClient(&goredis.Options{
  12. Addr: "localhost:6379",
  13. Password: "", // 没有设置密码
  14. DB: 0, // 使用默认的DB
  15. })
  16. Rdb = *rdb
  17. rh := rejson.NewReJSONHandler()
  18. rh.SetGoRedisClient(rdb)
  19. return *rdb
  20. }

我遇到了一个错误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

  1. package RedisModule
  2. import (
  3. "context"
  4. "fmt"
  5. goredis "github.com/go-redis/redis/v8"
  6. "github.com/nitishm/go-rejson"
  7. )
  8. var ctx = context.Background()
  9. var Rdb goredis.Client
  10. func ConfigureRedis() goredis.Client {
  11. rdb := goredis.NewClient(&goredis.Options{
  12. Addr: "localhost:6379",
  13. Password: "", // no password set
  14. DB: 0, // use default DB
  15. })
  16. Rdb = *rdb
  17. rh := rejson.NewReJSONHandler()
  18. rh.SetGoRedisClient(rdb)
  19. return *rdb
  20. }

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

huangapple
  • 本文由 发表于 2021年8月21日 06:33:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/68868655.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定