Skip to content
Golang Redis Rejson extension built upon go-redis
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
.gitignore
.travis.yml
LICENSE
README.md
constructors.go
extend_client.go
rejson_methods.go
rejson_methods_test.go
test_config.json

README.md

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.

You can’t perform that action at this time.