尝试连接 Redis JSON。

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

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

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:

确定