rejonson

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: Apache-2.0 Imports: 1 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"

The examples are using jonson library which is optional (but recommended)

Extend Client

We extend a client to add it all the rejson abilities, extended client will have all the go-redis functionality with all the rejson functionality.
Extended client is very comfortable to use because we don't need to pass a connection each time to some static method that accepts connection + args but instead just use the connection directly

goRedisClient := redis.NewClient(&redis.Options{
    Addr:     "localhost:6379",
    Password: "",
    DB:       0,
})
client := rejonson.ExtendClient(goRedisClient)
defer client.Close()

// client got all go-redis commands with 
json := jonson.New([]interface{}{"hello", "world", "rejson", "and", "rejonson", "are", "awesome", 1,2,3,4})
client.Set("go-redis-command", "hello", time.Second)
client.JsonSet("rejonson-json-command", ".", json.ToUnsafeJSONString())

arrLen, err := client.JsonArrLen("rejonson-json-command", ".").Result() // int command
if err != nil {
    // handle the error
}

fmt.Println("The array length is",  arrLen) // The array length is 11
Pipeline

Client will also return extended Pipeline and TXPipeline

pipeline := client.Pipeline()
pipeline.JsonNumMultBy("rejonson-json-command", "[7]", 10) // same array from the first example
pipeline.Set("go-redis-pipeline-command", "hello from go-redis", time.Second)

_, err = pipeline.Exec()
if err != nil {
    // handle error
}
jsonString, err := client.JsonGet("rejonson-json-command").Result()
if err != nil {
    fmt.Println(err.Error())
    // handle error
}
json = jonson.ParseUnsafe([]byte(jsonString))

fmt.Println(json.At(7).GetUnsafeFloat64()) // 10

API

Rejonson supports all the methods as described at ReJson Commands except for JSON.DEBUG and JSON.RESP. The arguments will be transferred to redis so please make sure you conform the rejson documentation.

Due to some rejson behavior #issue-76, empty strings will be ignored

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.

Dependencies

Rejonson got only single dependency which is go-redis. The testing got some other dependencies as well

Testing

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 got few dependencies of its' own:

Configuring Redis

In order to guarantee the code is safe for use The unit tests will have to use a real redis. To configure the connection edit the file test_config.json

redisConnection will just be passed to go-redis.Options, the keys should conform with the Options keys.
redisKeyPrefix is the prefix the unit tests will add to written test data at the redis (the data is deleted at the end of each test)

{
  "redisConnection": {
    "Addr":  "localhost:6379",
    "Password": "",
    "DB": 0
  },
  "redisKeyPrefix": "rejonson::tests::"
}

License

Apache 2.0

Contact

For any question or contribution, feel free to contact me at kromdan@gmail.com or 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(key, path string, jsons ...interface{}) *redis.IntCmd

func (Client) JsonArrIndex

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

func (Client) JsonArrInsert

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

func (Client) JsonArrLen

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

func (Client) JsonArrPop

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

func (Client) JsonArrTrim

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

func (Client) JsonDel

func (cl Client) JsonDel(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(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(key string, args ...interface{}) *redis.StringSliceCmd

func (Client) JsonNumIncrBy

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

func (Client) JsonNumMultBy

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

func (Client) JsonObjKeys

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

func (Client) JsonObjLen

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

func (Client) JsonSet

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

jsonSet

Possible args: (Optional)

func (Client) JsonStrAppend

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

func (Client) JsonStrLen

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

func (Client) JsonType

func (cl Client) JsonType(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(key, path string, jsons ...interface{}) *redis.IntCmd

func (Pipeline) JsonArrIndex

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

func (Pipeline) JsonArrInsert

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

func (Pipeline) JsonArrLen

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

func (Pipeline) JsonArrPop

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

func (Pipeline) JsonArrTrim

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

func (Pipeline) JsonDel

func (cl Pipeline) JsonDel(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(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(key string, args ...interface{}) *redis.StringSliceCmd

func (Pipeline) JsonNumIncrBy

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

func (Pipeline) JsonNumMultBy

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

func (Pipeline) JsonObjKeys

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

func (Pipeline) JsonObjLen

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

func (Pipeline) JsonSet

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

jsonSet

Possible args: (Optional)

func (Pipeline) JsonStrAppend

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

func (Pipeline) JsonStrLen

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

func (Pipeline) JsonType

func (cl Pipeline) JsonType(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