rejonson

package module
v8.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

Rejonson

Redis rejson extension built upon go-redis

Build Status Coverage Status

Table of Contents

  1. Quick start
  2. API
  3. Dependencies
  4. Testing
  5. License
  6. Contact

Quick start

Install
go get github.com/KromDaniel/rejonson
Import
import "github.com/KromDaniel/rejonson"
Extend Client

Extends go-redis client with all ReJSON abilities, so you can use directly the rejson client for all redis usage and commands.

// go redis client
goRedisClient := redis.NewClient(&redis.Options{
  Addr: "localhost:6379",
})

client := rejonson.ExtendClient(goRedisClient)
defer client.Close()

arr := []interface{}{"hello", "world", 1, map[string]interface{}{"key": 12}}
js, err := json.Marshal(arr)
if err != nil {
  // handle
}
// redis "native" command
client.Set("go-redis-cmd", "hello", time.Second)
// rejson command
client.JsonSet("rejson-cmd", ".", string(js))

// int command
arrLen, err := client.JsonArrLen("rejson-cmd", ".").Result()
if err != nil {
  // handle
}

fmt.Printf("Array length: %d", arrLen)
// Output: Array length: 4
Pipeline

Client will also return extended Pipeline and TXPipeline

goRedisClient := redis.NewClient(&redis.Options{
  Addr: "localhost:6379",
})

client := rejonson.ExtendClient(goRedisClient)

pipeline := client.Pipeline()
pipeline.JsonSet("rejson-cmd-pipeline", ".", "[10]")
pipeline.JsonNumMultBy("rejson-cmd-pipeline", "[0]", 10)
pipeline.Set("go-redis-pipeline-command", "hello from go-redis", time.Second)

_, err := pipeline.Exec()
if err != nil {
  // handle error
}
jsonString, err := client.JsonGet("rejson-cmd-pipeline").Result()
if err != nil {
  // handle error
}

fmt.Printf("Array %s", jsonString)

// Output: Array [100]

API

Rejonson implements all the methods as described at ReJson Commands except for JSON.DEBUG and JSON.RESP.

The args will be serialized to redis directly so make sure to read ReJSON command docs

All the rejson methods starts with the prefix of Json e.g JsonDel, JsonArrIndex, JsonMGet.
Each command returns specific go-redis.Cmder by the specific request.


Due to some ReJSON bug - #issue-76, some empty strings will be ignored.

Dependencies

Rejonson depends only on go-redis. The testing also depends on assert library.

Test

Rejonson tests must use real redis with ReJson to run

It is recommended to run the unit tests when using rejonson.
The unit tests will make sure your go-redis version is compatible and your rejson plugin supports all the methods and working as expected.

The testing library depends on assert library

License

Apache 2.0

Contact

For any question or contribution, feel free to open an issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*redis.Client
	// contains filtered or unexported fields
}

Client is an extended redis.Client, stores a pointer to the original redis.Client

func ExtendClient

func ExtendClient(client *redis.Client) *Client

func (Client) JsonArrAppend

func (cl Client) JsonArrAppend(ctx context.Context, key, path string, jsons ...interface{}) *redis.IntCmd

func (Client) JsonArrIndex

func (cl Client) JsonArrIndex(ctx context.Context, key, path string, jsonScalar interface{}, startAndStop ...interface{}) *redis.IntCmd

func (Client) JsonArrInsert

func (cl Client) JsonArrInsert(ctx context.Context, key, path string, index int, jsons ...interface{}) *redis.IntCmd

func (Client) JsonArrLen

func (cl Client) JsonArrLen(ctx context.Context, key, path string) *redis.IntCmd

func (Client) JsonArrPop

func (cl Client) JsonArrPop(ctx context.Context, key, path string, index int) *redis.StringCmd

func (Client) JsonArrTrim

func (cl Client) JsonArrTrim(ctx context.Context, key, path string, start, stop int) *redis.IntCmd

func (Client) JsonDel

func (cl Client) JsonDel(ctx context.Context, key, path string) *redis.IntCmd

JsonDel

returns intCmd -> deleted 1 or 0 read more: https://oss.redislabs.com/rejson/commands/#jsondel

func (Client) JsonGet

func (cl Client) JsonGet(ctx context.Context, key string, args ...interface{}) *redis.StringCmd

JsonGet

Possible args:

(Optional) INDENT + indent-string (Optional) NEWLINE + line-break-string (Optional) SPACE + space-string (Optional) NOESCAPE (Optional) path ...string

returns stringCmd -> the JSON string read more: https://oss.redislabs.com/rejson/commands/#jsonget

func (Client) JsonMGet

func (cl Client) JsonMGet(ctx context.Context, key string, args ...interface{}) *redis.StringSliceCmd

func (Client) JsonNumIncrBy

func (cl Client) JsonNumIncrBy(ctx context.Context, key, path string, num int) *redis.StringCmd

func (Client) JsonNumMultBy

func (cl Client) JsonNumMultBy(ctx context.Context, key, path string, num int) *redis.StringCmd

func (Client) JsonObjKeys

func (cl Client) JsonObjKeys(ctx context.Context, key, path string) *redis.StringSliceCmd

func (Client) JsonObjLen

func (cl Client) JsonObjLen(ctx context.Context, key, path string) *redis.IntCmd

func (Client) JsonSet

func (cl Client) JsonSet(ctx context.Context, key, path, json string, args ...interface{}) *redis.StatusCmd

jsonSet

Possible args: (Optional)

func (Client) JsonStrAppend

func (cl Client) JsonStrAppend(ctx context.Context, key, path, appendString string) *redis.IntCmd

func (Client) JsonStrLen

func (cl Client) JsonStrLen(ctx context.Context, key, path string) *redis.IntCmd

func (Client) JsonType

func (cl Client) JsonType(ctx context.Context, key, path string) *redis.StringCmd

func (*Client) Pipeline

func (cl *Client) Pipeline() *Pipeline

func (*Client) TXPipeline

func (cl *Client) TXPipeline() *Pipeline

type Pipeline

type Pipeline struct {
	redis.Pipeliner
	// contains filtered or unexported fields
}

Pipeline is an extended redis.Pipeline, stores a pointer to the original redis.Pipeliner

func ExtendPipeline

func ExtendPipeline(pipeline redis.Pipeliner) *Pipeline

func (Pipeline) JsonArrAppend

func (cl Pipeline) JsonArrAppend(ctx context.Context, key, path string, jsons ...interface{}) *redis.IntCmd

func (Pipeline) JsonArrIndex

func (cl Pipeline) JsonArrIndex(ctx context.Context, key, path string, jsonScalar interface{}, startAndStop ...interface{}) *redis.IntCmd

func (Pipeline) JsonArrInsert

func (cl Pipeline) JsonArrInsert(ctx context.Context, key, path string, index int, jsons ...interface{}) *redis.IntCmd

func (Pipeline) JsonArrLen

func (cl Pipeline) JsonArrLen(ctx context.Context, key, path string) *redis.IntCmd

func (Pipeline) JsonArrPop

func (cl Pipeline) JsonArrPop(ctx context.Context, key, path string, index int) *redis.StringCmd

func (Pipeline) JsonArrTrim

func (cl Pipeline) JsonArrTrim(ctx context.Context, key, path string, start, stop int) *redis.IntCmd

func (Pipeline) JsonDel

func (cl Pipeline) JsonDel(ctx context.Context, key, path string) *redis.IntCmd

JsonDel

returns intCmd -> deleted 1 or 0 read more: https://oss.redislabs.com/rejson/commands/#jsondel

func (Pipeline) JsonGet

func (cl Pipeline) JsonGet(ctx context.Context, key string, args ...interface{}) *redis.StringCmd

JsonGet

Possible args:

(Optional) INDENT + indent-string (Optional) NEWLINE + line-break-string (Optional) SPACE + space-string (Optional) NOESCAPE (Optional) path ...string

returns stringCmd -> the JSON string read more: https://oss.redislabs.com/rejson/commands/#jsonget

func (Pipeline) JsonMGet

func (cl Pipeline) JsonMGet(ctx context.Context, key string, args ...interface{}) *redis.StringSliceCmd

func (Pipeline) JsonNumIncrBy

func (cl Pipeline) JsonNumIncrBy(ctx context.Context, key, path string, num int) *redis.StringCmd

func (Pipeline) JsonNumMultBy

func (cl Pipeline) JsonNumMultBy(ctx context.Context, key, path string, num int) *redis.StringCmd

func (Pipeline) JsonObjKeys

func (cl Pipeline) JsonObjKeys(ctx context.Context, key, path string) *redis.StringSliceCmd

func (Pipeline) JsonObjLen

func (cl Pipeline) JsonObjLen(ctx context.Context, key, path string) *redis.IntCmd

func (Pipeline) JsonSet

func (cl Pipeline) JsonSet(ctx context.Context, key, path, json string, args ...interface{}) *redis.StatusCmd

jsonSet

Possible args: (Optional)

func (Pipeline) JsonStrAppend

func (cl Pipeline) JsonStrAppend(ctx context.Context, key, path, appendString string) *redis.IntCmd

func (Pipeline) JsonStrLen

func (cl Pipeline) JsonStrLen(ctx context.Context, key, path string) *redis.IntCmd

func (Pipeline) JsonType

func (cl Pipeline) JsonType(ctx context.Context, key, path string) *redis.StringCmd

func (*Pipeline) Pipeline

func (pl *Pipeline) Pipeline() *Pipeline

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL