Golang client for redislabs' ReJSON module with support for multilple redis clients (redigo, go-redis)

Overview

Go-ReJSON - a golang client for ReJSON (a JSON data type for Redis)

Go-ReJSON is a Go client for ReJSON Redis Module.

Go Reference test code-analysis codecov Go Report Card GitHub release

ReJSON is a Redis module that implements ECMA-404 The JSON Data Interchange Standard as a native data type. It allows storing, updating and fetching JSON values from Redis keys (documents).

Primary features of ReJSON Module:

* Full support of the JSON standard
* JSONPath-like syntax for selecting element inside documents
* Documents are stored as binary data in a tree structure, allowing fast access to sub-elements
* Typed atomic operations for all JSON values types

Each and every feature of ReJSON Module is fully incorporated in the project.

Enjoy ReJSON with the type-safe Redis client, Go-Redis/Redis or use the print-like Redis-api client GoModule/Redigo. Go-ReJSON supports both the clients. Use any of the above two client you want, Go-ReJSON helps you out with all its features and functionalities in a more generic and standard way.

Support for mediocregopher/radix and other Redis clients is in our RoadMap. Any contributions on the support for other clients is hearty welcome.

Installation

go get github.com/nitishm/go-rejson

Example usage

package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"log"

	"github.com/nitishm/go-rejson/v4"
	goredis "github.com/go-redis/redis/v8"
	"github.com/gomodule/redigo/redis"
)

// Name - student name
type Name struct {
	First  string `json:"first,omitempty"`
	Middle string `json:"middle,omitempty"`
	Last   string `json:"last,omitempty"`
}

// Student - student object
type Student struct {
	Name Name `json:"name,omitempty"`
	Rank int  `json:"rank,omitempty"`
}

func Example_JSONSet(rh *rejson.Handler) {

	student := Student{
		Name: Name{
			"Mark",
			"S",
			"Pronto",
		},
		Rank: 1,
	}
	res, err := rh.JSONSet("student", ".", student)
	if err != nil {
		log.Fatalf("Failed to JSONSet")
		return
	}

	if res.(string) == "OK" {
		fmt.Printf("Success: %s\n", res)
	} else {
		fmt.Println("Failed to Set: ")
	}

	studentJSON, err := redis.Bytes(rh.JSONGet("student", "."))
	if err != nil {
		log.Fatalf("Failed to JSONGet")
		return
	}

	readStudent := Student{}
	err = json.Unmarshal(studentJSON, &readStudent)
	if err != nil {
		log.Fatalf("Failed to JSON Unmarshal")
		return
	}

	fmt.Printf("Student read from redis : %#v\n", readStudent)
}

func main() {
	var addr = flag.String("Server", "localhost:6379", "Redis server address")

	rh := rejson.NewReJSONHandler()
	flag.Parse()

	// Redigo Client
	conn, err := redis.Dial("tcp", *addr)
	if err != nil {
		log.Fatalf("Failed to connect to redis-server @ %s", *addr)
	}
	defer func() {
		_, err = conn.Do("FLUSHALL")
		err = conn.Close()
		if err != nil {
			log.Fatalf("Failed to communicate to redis-server @ %v", err)
		}
	}()
	rh.SetRedigoClient(conn)
	fmt.Println("Executing Example_JSONSET for Redigo Client")
	Example_JSONSet(rh)

	// GoRedis Client
	cli := goredis.NewClient(&goredis.Options{Addr: *addr})
	defer func() {
		if err := cli.FlushAll().Err(); err != nil {
			log.Fatalf("goredis - failed to flush: %v", err)
		}
		if err := cli.Close(); err != nil {
			log.Fatalf("goredis - failed to communicate to redis-server: %v", err)
		}
	}()
	rh.SetGoRedisClient(cli)
	fmt.Println("\nExecuting Example_JSONSET for Redigo Client")
	Example_JSONSet(rh)
}
Issues
  • Switch over to go modules from dep for dependency management

    Switch over to go modules from dep for dependency management

    Difficulty: Introductory up-for-grabs 
    opened by nitishm 23
  • Support go-redis as the redis client

    Support go-redis as the redis client

    The goal of this feature is to add support for more redis clients like go-rejson, gosexy/redis,etc., rather than have it tightly coupled with redigo, which is how it is currently written to work.

    The go-rejson library relies on the redigo.Conn object, which is passed in as a dependencies to each of the exported methods, which in turn rely on the Do() method of the redigo.Conn object.

    See JSONSet - https://github.com/nitishm/go-rejson/blob/master/rejson.go#L273-L279

    The feature/enhancement should keep the library backwards compatible (if possible) by abstracting away the conn.Do() method, in a way that it works with all supported client libraries.

    Difficulty: Advanced enhancement help wanted up-for-grabs 
    opened by nitishm 11
  • Set Go Redis V7 Client Problem

    Set Go Redis V7 Client Problem

    HI, I want so set the goredis/v7 to use rejson, but when I set the client,

    the error shows:

    Cannot use (type *"github.com/go-redis/redis/v7".Client) as type *"github.com/go-redis/redis".Client 
    

    looks like the lib only accept "github.com/go-redis/redis" (v6),

    can fix the problem? thanks..

    opened by rainlay 11
  • cannot use cli (type *

    cannot use cli (type *"github.com/go-redis/redis".Client) as type *"github.com/nitishm/go-rejson/vendor/github.com/go-redis/redis".Client in argument to rh.SetGoRedisClientgo

    Error: cannot use cli (type *"github.com/go-redis/redis".Client) as type *"github.com/nitishm/go-rejson/vendor/github.com/go-redis/redis".Client in argument to rh.SetGoRedisClientgo

    When trying to run example code on like 97:

    rh.SetGoRedisClient(cli)
    
    opened by tghastings 7
  • Add gometalinter to travis ci #20

    Add gometalinter to travis ci #20

    #20 I added in gometalinter to travisci in this repo. Gometalinter uses the following lint method.

    gometalinter --concurrency=4 --enable-gc --deadline=300s --disable-all 
    --enable=deadcode
    --enable=errcheck
    --enable=goconst
    --enable=gofmt 
    --enable=goimports
    --enable=golint
    --exclude=.pb.go
    --enable=gotype
    --enable=ineffassign
    --enable=interfacer
    --enable=lll --line-length=120 
    --enable=misspell 
    --enable=structcheck 
    --enable=unconvert 
    --enable=unused 
    --enable=varcheck 
    --enable=vet 
    --enable=maligned 
    --vendor ./...
    

    https://github.com/alecthomas/gometalinter#supported-linters

    I would like to know whether you want to use supported linters else.

    opened by u5surf 7
  • Support for various clients

    Support for various clients

    Moving forward on the proposed work in the issue https://github.com/nitishm/go-rejson/issues/27#issuecomment-453861407

    The project now, is all set to implement the ReJSON commands for various clients.

    Checklist to implement gomodule/redigo client:

    • [x] Interface setup and other stuffs to be used during client implementation
    • [x] ~~Abstracting options for other commands like JSON.ARRINDEX and JSON.ARRPOP, as done forJSON.GET and JSON.SET~~

    Edited: I think their abstraction is not much required, they are very well maintained rigthnow

    • [x] Adding proper examples and details in comments so that the godoc of the repo will be improved
    • [x] Implementation of commands in gomodule/redigo
    • [x] Adding proper test cases for clients

    Similarly, for other clients:

    • [x] gomodule/redigo
    • [x] go-redis/redis

    Support for mediocregopher/radix is moved to the future roadmap

    opened by Shivam010 6
  • swap from Go Dep to Go Modules

    swap from Go Dep to Go Modules

    This further address issue #31

    opened by nicfb 3
  • Installation step does not work

    Installation step does not work

    Describe the bug go get github.com/nitishm/go-rejson throws the following error

    "package github.com/go-redis/redis/v7: cannot find package "github.com/go-redis/redis/v7" in any of"

    To Reproduce go get github.com/nitishm/go-rejson

    Expected behavior Package should install properly

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information): macOS 10.15.5

    question 
    opened by esker 3
  • Set Go Redis V8 Client Problem

    Set Go Redis V8 Client Problem

    Hi,

    I wanted to report incompatibilities with v8 of go-redis. According to go-redis documentation, v8 is the latest recommended version.

    Very similar to the issue concerning upgrading from go-redis v6 to v7.

    opened by cyberbeast 3
  • Suggestion for Go build version and Staticcheck and Commands Added

    Suggestion for Go build version and Staticcheck and Commands Added

    Suggestion for new Go build version in travis and Code Reviewer

    • Removing go 1.9.x and tip
    • Adding go 1.11.x
    • Staticcheck offers extensive and customizable code analysis and review. It would be best for the job.
    • Command JSON.OBJKEYS added: https://oss.redislabs.com/rejson/commands/#jsonobjkeys
    • Command JSON.OBJLEN added: https://oss.redislabs.com/rejson/commands/#jsonobjlen
    • Command JSON.DEBUG added: https://oss.redislabs.com/rejson/commands/#jsondebug

    Fix for issue: #10, #11, #12, #16

    opened by Shivam010 3
  • Call a command inside a transaction/pipe

    Call a command inside a transaction/pipe

    Is there a way to use a rejson command inside a transaction or pipe? Something like that:

    tx := redisClient.TXPipeline()
    tx.XAdd(&redis.XAddArgs{Stream: stream.Name, ID: "*", Values: map[string]interface{}{"msg": "New stream"}})
    tx.JSONSet(streamInfoKey(stream.Name), ".", stream)
    tx.Exec()
    
    opened by luizvnasc 1
  • JSONQGet + JSON.INDEX ADD

    JSONQGet + JSON.INDEX ADD

    Created functions to use the RedisJSON2 JSON.QGet, JSON.INDEX add and a JSON.SETWithIndex

    opened by gatomazi 1
  • Create a JSONQGet function

    Create a JSONQGet function

    RedisJSON2 was released, and with it has the funcionality of make GET with Queries, which is called JSON.QGET. So, I wanted to do the same in Go, and it didn't was avaiable yet.

    With this in mind, I created the command to execute de JSON.QGET with go-rejson, and I'd like to know what could I do to improve the code, and if we could do a PR, for others who need use it.

    Or if there is another way to do it and I didn't find, please tell me.

    Its forked on my repo

    opened by gatomazi 1
  • Mocking ReJSON in a mock redis server

    Mocking ReJSON in a mock redis server

    Is there any way to mock rejson in a mocked Redis server in golang?

    I am able to mock a Redis server using something like this using miniredis and redismock

    func newTestRedis() (*redismock.ClientMock, *redis.Client) {
    	mr, err := miniredis.Run()
    	if err != nil {
    		panic(err)
    	}
    	client := redis.NewClient(&redis.Options{
    		Addr: mr.Addr(),
    	})
    	return redismock.NewNiceMock(client.Client), client
    }
    

    It is able to do normal Redis operations like Get, Set but since I am using ReJSON module, I am not able to run any ReJSON commands on that.

    Thanks

    opened by kpiyush17 2
  • Using JSON.SET with expiry

    Using JSON.SET with expiry

    Is your feature request related to a problem? Please describe.

    As described here https://github.com/RedisJSON/RedisJSON/issues/56. I want to set a json key with some expiry. However, I understand it is not supported by ReJSON directly how could I use go-rejson to solve this? Is this supported ? If not I would be willing to help out. Any pointers would be helpful.

    Describe the solution you'd like A command like JSONSetWithExpiry to set expiry for a JSON Key.

    Describe alternatives you've considered I guess I could accomplish this using the underlying redis client but since I will be using your library, a method like JSONSetWithExpiry would be a nice abstraction.

    Difficulty: Intermediate help wanted up-for-grabs 
    opened by jatinsandilya 5
  • Manage releases using an automated tool like goreleaser

    Manage releases using an automated tool like goreleaser

    Now that we have our first release https://github.com/nitishm/go-rejson/releases/tag/v1.0.0, it makes sense to automate the release process using https://github.com/goreleaser/goreleaser

    Difficulty: Introductory good first issue up-for-grabs 
    opened by nitishm 1
Releases(v4.0.0)
  • v4.0.0(Dec 26, 2020)

    • This release will upgrade the version of go-redis/redis from v7.4.0 to v8.4.4.
    • Also, this will now support command level Context handling as supported by go-redis.
    • And as redigo does not support Context yet the method SetContext will be meaningless for the client, and it's will be backward compatible.
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Jul 16, 2020)

    This release will upgrade the version of the following:

    • go-redis/redis from v6.15.1 to v7.4.0
    • gomodule/redigo to v1.8.2
    • golang version to 1.14

    Note: Though golang version is marked as 1.14, you can use go-rejson with any go version supporting Go modules

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Jan 27, 2019)

    Version 2.0.0 provides support for go-redis while breaking backwards compatibility.

    • Major changes in the library provide abstractions for multiple redis clients (redigo and go-redis).
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jan 13, 2019)

    v1.0.0

    This release of the go-rejson library, is a feature complete implementation of the ReJSON module in Go.

    NOTE: The v1.0.0 release is tightly coupled with redigo, Redis Go Client library and does not support other client libraries.

    Source code(tar.gz)
    Source code(zip)
Owner
Nitish Malhotra
Senior Software Engineer @microsoft C+AI University of Pennsylvania Alum Past:Oracle/CSPi/HERE technologies Focus: Golang, Kubernetes, Istio, DevOps
Nitish Malhotra
Go client for Redis

Redigo Redigo is a Go client for the Redis database. Features A Print-like API with support for all Redis commands. Pipelining, including pipelined tr

null 8.4k Jun 12, 2021
Go Redis Client

xredis Built on top of github.com/garyburd/redigo with the idea to simplify creating a Redis client, provide type safe calls and encapsulate the low l

Raed Shomali 15 Jun 2, 2021
Redis Sorted Sets Benchmark

redis-zbench-go Redis Sorted Sets Benchmark Overview This repo contains code to trigger load ( ZADD ) or query (ZRANGEBYLEX key min max) benchmarks, w

filipe oliveira 3 May 18, 2021
Type-safe Redis client for Golang

Redis client for Golang ❤️ Uptrace.dev - distributed traces, logs, and errors in one place Join Discord to ask questions. Documentation Reference Exam

null 11.7k Jun 13, 2021
Type-safe Redis client for Golang

Redis client for Golang ❤️ Uptrace.dev - distributed traces, logs, and errors in one place Join Discord to ask questions. Documentation Reference Exam

null 11.7k Jun 13, 2021
Distributed WebSocket broker

dSock dSock is a distributed WebSocket broker (in Go, using Redis). Clients can authenticate & connect, and you can send text/binary message as an API

Charles Crete 198 Apr 13, 2021
Simple key-value store abstraction and implementations for Go (Redis, Consul, etcd, bbolt, BadgerDB, LevelDB, Memcached, DynamoDB, S3, PostgreSQL, MongoDB, CockroachDB and many more)

gokv Simple key-value store abstraction and implementations for Go Contents Features Simple interface Implementations Value types Marshal formats Road

Philipp Gillé 343 Jun 15, 2021
Google Go Client and Connectors for Redis

Go-Redis Go Clients and Connectors for Redis. The initial release provides the interface and implementation supporting the (~) full set of current Red

Joubin Houshyar 434 Jun 9, 2021
redis client implement by golang, inspired by jedis.

godis redis client implement by golang, refers to jedis. this library implements most of redis command, include normal redis command, cluster command,

piaohao 89 Apr 7, 2021
Redis client library for Go

go-redis go-redis is a Redis client library for the Go programming language. It's built on the skeleton of gomemcache. It is safe to use by multiple g

Alexandre Fiori 45 Jul 14, 2020
Redis client Mock Provide mock test for redis query

Redis client Mock Provide mock test for redis query, Compatible with github.com/go-redis/redis/v8 Install Confirm that you are using redis.Client the

null 35 Jun 12, 2021
Aerospike Client Go

Aerospike Go Client An Aerospike library for Go. This library is compatible with Go 1.9+ and supports the following operating systems: Linux, Mac OS X

Aerospike 365 Jun 3, 2021
A pure go library to handle MySQL network protocol and replication.

A pure go library to handle MySQL network protocol and replication.

null 3.1k Jun 21, 2021
Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package

Go-MySQL-Driver A MySQL-Driver for Go's database/sql package Features Requirements Installation Usage DSN (Data Source Name) Password Protocol Address

Go SQL Drivers 11k Jun 12, 2021