All Projects → KromDaniel → rejonson

KromDaniel / rejonson

Licence: other
Golang Redis Rejson extension built upon go-redis

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to rejonson

redis
go 版本 redis 仿写
Stars: ✭ 21 (-8.7%)
Mutual labels:  go-redis
redis-browser
Cross platform GUI tool for redis that includes support for ReJSON
Stars: ✭ 29 (+26.09%)
Mutual labels:  rejson
laya-template
服务基本框架,template
Stars: ✭ 13 (-43.48%)
Mutual labels:  go-redis
redisstore
A Gorilla Sessions Store implementation backed by Redis
Stars: ✭ 46 (+100%)
Mutual labels:  go-redis
redismock
Redis client Mock
Stars: ✭ 164 (+613.04%)
Mutual labels:  go-redis
redis-modules-sdk-ts
A Software development kit for easier connection and execution of Redis Modules commands.
Stars: ✭ 152 (+560.87%)
Mutual labels:  rejson

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].