Documentation ¶
Overview ¶
Go-ReJSON is a Go client for ReJSON redis module (https://github.com/RedisLabsModules/rejson)
ReJSON is a Redis module that aims to provide full support for 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
Go-ReJSON implements all the features of ReJSON Module, without any dependency on the client used for Redis in GoLang.
Enjoy ReJSON with the type-safe Redis client, Go-Redis/Redis (https://github.com/go-redis/redis) or use the print-like Redis-api client GoModule/Redigo (https://github.com/gomodule/redigo/redis).
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.
Installation ¶
To install and use ReJSON module, one must have the pre-requisites installed and setup. Run the script in :
./install-redis-rejson.sh
Examples ¶
Create New ReJSON Handler
rh := rejson.NewReJSONHandler()
Set Redigo Client and use ReJSON in it
conn, _ := redis.Dial("tcp", *addr) rh.SetRedigoClient(conn)
Similarly, one can set client for Go-Redis
cli := goredis.NewClient(&goredis.Options{Addr: *addr}) rh.SetGoRedisClient(cli)
And now, one can directly use ReJSON commands using the handler
res, err := rh.JSONSet("str", ".", "string")
Index ¶
- type Handler
- func (r *Handler) JSONArrAppend(key, path string, values ...interface{}) (res interface{}, err error)
- func (r *Handler) JSONArrIndex(key, path string, jsonValue interface{}, optionalRange ...int) (res interface{}, err error)
- func (r *Handler) JSONArrInsert(key, path string, index int, values ...interface{}) (res interface{}, err error)
- func (r *Handler) JSONArrLen(key, path string) (res interface{}, err error)
- func (r *Handler) JSONArrPop(key, path string, index int) (res interface{}, err error)
- func (r *Handler) JSONArrTrim(key, path string, start, end int) (res interface{}, err error)
- func (r *Handler) JSONDebug(subCmd rjs.DebugSubCommand, key, path string) (res interface{}, err error)
- func (r *Handler) JSONDel(key string, path string) (res interface{}, err error)
- func (r *Handler) JSONForget(key, path string) (res interface{}, err error)
- func (r *Handler) JSONGet(key, path string, opts ...rjs.GetOption) (res interface{}, err error)
- func (r *Handler) JSONMGet(path string, keys ...string) (res interface{}, err error)
- func (r *Handler) JSONNumIncrBy(key, path string, number int) (res interface{}, err error)
- func (r *Handler) JSONNumMultBy(key, path string, number int) (res interface{}, err error)
- func (r *Handler) JSONObjKeys(key, path string) (res interface{}, err error)
- func (r *Handler) JSONObjLen(key, path string) (res interface{}, err error)
- func (r *Handler) JSONResp(key, path string) (res interface{}, err error)
- func (r *Handler) JSONSet(key string, path string, obj interface{}, opts ...rjs.SetOption) (res interface{}, err error)
- func (r *Handler) JSONStrAppend(key, path, jsonstring string) (res interface{}, err error)
- func (r *Handler) JSONStrLen(key, path string) (res interface{}, err error)
- func (r *Handler) JSONType(key, path string) (res interface{}, err error)
- func (r *Handler) SetClientInactive()
- func (r *Handler) SetContext(ctx context.Context) *Handler
- func (r *Handler) SetGoRedisClient(conn clients.GoRedisClientConn)deprecated
- func (r *Handler) SetGoRedisClientWithContext(ctx context.Context, conn clients.GoRedisClientConn)
- func (r *Handler) SetRedigoClient(conn clients.RedigoClientConn)
- type ReJSON
- type RedisClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewReJSONHandler ¶
func NewReJSONHandler() *Handler
func (*Handler) JSONArrAppend ¶
func (r *Handler) JSONArrAppend(key, path string, values ...interface{}) (res interface{}, err error)
JSONArrAppend to append json value into array at path
ReJSON syntax:
JSON.ARRAPPEND <key> <path> <json> [json ...]
func (*Handler) JSONArrIndex ¶
func (r *Handler) JSONArrIndex(key, path string, jsonValue interface{}, optionalRange ...int) ( res interface{}, err error, )
JSONArrIndex returns the index of the json element provided and return -1 if element is not present
ReJSON syntax:
JSON.ARRINDEX <key> <path> <json-scalar> [start [stop]]
func (*Handler) JSONArrInsert ¶
func (r *Handler) JSONArrInsert(key, path string, index int, values ...interface{}) (res interface{}, err error)
JSONArrInsert inserts the json value(s) into the array at path before the index (shifts to the right).
ReJSON syntax:
JSON.ARRINSERT <key> <path> <index> <json> [json ...]
func (*Handler) JSONArrLen ¶
JSONArrLen returns the length of the json array at path
ReJSON syntax:
JSON.ARRLEN <key> [path]
func (*Handler) JSONArrPop ¶
JSONArrPop removes and returns element from the index in the array to pop last element use rejson.PopArrLast
ReJSON syntax:
JSON.ARRPOP <key> [path [index]]
func (*Handler) JSONArrTrim ¶
JSONArrTrim trims an array so that it contains only the specified inclusive range of elements
ReJSON syntax:
JSON.ARRTRIM <key> <path> <start> <stop>
func (*Handler) JSONDebug ¶
func (r *Handler) JSONDebug(subCmd rjs.DebugSubCommand, key, path string) (res interface{}, err error)
JSONDebug reports information
ReJSON syntax:
JSON.DEBUG <subcommand & arguments> JSON.DEBUG MEMORY <key> [path] - report the memory usage in bytes of a value. path defaults to root if not provided. JSON.DEBUG HELP - reply with a helpful message
func (*Handler) JSONForget ¶
JSONForget is an alias for JSONDel
ReJSON syntax:
JSON.FORGET <key> [path]
func (*Handler) JSONGet ¶
JSONGet used to get a json object
ReJSON syntax:
JSON.GET <key> [INDENT indentation-string] [NEWLINE line-break-string] [SPACE space-string] [NOESCAPE] [path ...]
func (*Handler) JSONMGet ¶
JSONMGet used to get path values from multiple keys
ReJSON syntax:
JSON.MGET <key> [key ...] <path>
func (*Handler) JSONNumIncrBy ¶
JSONNumIncrBy to increment a number by provided amount
ReJSON syntax:
JSON.NUMINCRBY <key> <path> <number>
func (*Handler) JSONNumMultBy ¶
JSONNumMultBy to increment a number by provided amount
ReJSON syntax:
JSON.NUMMULTBY <key> <path> <number>
func (*Handler) JSONObjKeys ¶
JSONObjKeys returns the keys in the object that's referenced by path
ReJSON syntax:
JSON.OBJKEYS <key> [path]
func (*Handler) JSONObjLen ¶
JSONObjLen report the number of keys in the JSON Object at path in key
ReJSON syntax:
JSON.OBJLEN <key> [path]
func (*Handler) JSONResp ¶
JSONResp returns the JSON in key in Redis Serialization Protocol (RESP).
ReJSON syntax:
JSON.RESP <key> [path]
func (*Handler) JSONSet ¶
func (r *Handler) JSONSet(key string, path string, obj interface{}, opts ...rjs.SetOption) ( res interface{}, err error, )
JSONSet used to set a json object
ReJSON syntax:
JSON.SET <key> <path> <json> [NX | XX]
func (*Handler) JSONStrAppend ¶
JSONStrAppend to append a jsonstring to an existing member
ReJSON syntax:
JSON.STRAPPEND <key> [path] <json-string>
func (*Handler) JSONStrLen ¶
JSONStrLen to return the length of a string member
ReJSON syntax:
JSON.STRLEN <key> [path]
func (*Handler) JSONType ¶
JSONType to get the type of key or member at path.
ReJSON syntax:
JSON.TYPE <key> [path]
func (*Handler) SetClientInactive ¶
func (r *Handler) SetClientInactive()
SetClientInactive resets the handler and unset any client, set to the handler
func (*Handler) SetContext ¶
SetContext helps redis-clients, provide use of command level context in the ReJSON commands. Currently, only go-redis@v8 supports command level context, therefore a separate method is added to support it, maintaining the support for other clients and for backward compatibility. (nitishm/go-rejson#46)
func (*Handler) SetGoRedisClient
deprecated
func (r *Handler) SetGoRedisClient(conn clients.GoRedisClientConn)
Deprecated: SetGoRedisClient sets Go-Redis (https://github.com/go-redis/redis) client to the handler. It is left for backward compatibility.
func (*Handler) SetGoRedisClientWithContext ¶
func (r *Handler) SetGoRedisClientWithContext(ctx context.Context, conn clients.GoRedisClientConn)
SetGoRedisClientWithContext sets Go-Redis (https://github.com/go-redis/redis) client to the handler with a global context for the connection
func (*Handler) SetRedigoClient ¶
func (r *Handler) SetRedigoClient(conn clients.RedigoClientConn)
SetRedigoClient sets Redigo (https://github.com/gomodule/redigo/redis) client to the handler
type ReJSON ¶
type ReJSON interface { JSONSet(key, path string, obj interface{}, opts ...rjs.SetOption) (res interface{}, err error) JSONGet(key, path string, opts ...rjs.GetOption) (res interface{}, err error) JSONMGet(path string, keys ...string) (res interface{}, err error) JSONDel(key, path string) (res interface{}, err error) JSONType(key, path string) (res interface{}, err error) JSONNumIncrBy(key, path string, number int) (res interface{}, err error) JSONNumMultBy(key, path string, number int) (res interface{}, err error) JSONStrAppend(key, path string, jsonstring string) (res interface{}, err error) JSONStrLen(key, path string) (res interface{}, err error) JSONArrAppend(key, path string, values ...interface{}) (res interface{}, err error) JSONArrLen(key, path string) (res interface{}, err error) JSONArrPop(key, path string, index int) (res interface{}, err error) JSONArrIndex(key, path string, jsonValue interface{}, optionalRange ...int) (res interface{}, err error) JSONArrTrim(key, path string, start, end int) (res interface{}, err error) JSONArrInsert(key, path string, index int, values ...interface{}) (res interface{}, err error) JSONObjKeys(key, path string) (res interface{}, err error) JSONObjLen(key, path string) (res interface{}, err error) JSONDebug(subCmd rjs.DebugSubCommand, key, path string) (res interface{}, err error) JSONForget(key, path string) (res interface{}, err error) JSONResp(key, path string) (res interface{}, err error) }
ReJSON provides an interface for various Go Redis Clients to implement ReJSON commands
type RedisClient ¶
type RedisClient interface { SetClientInactive() SetRedigoClient(conn clients.RedigoClientConn) SetGoRedisClient(conn clients.GoRedisClientConn) }
RedisClient provides interface for Client handling in the ReJSON Handler