Documentation - Redise Pack

A guide to Redise Pack installation, operation and administration

open all | close all

ReJSON Quick Start

Note: This page only pertains to Redis Enterprise Pack v5.0 Preview.

For this quick start, you will need the following:

  • A Redis Enterprise Pack cluster with setup already complete
  • Any redis-cli or ReJSON enabled client

Add ReJSON module to Redis Enterprise Pack cluster

Before doing anything, you must download and install the ReJSON package in to your cluster.

Download the module
$ curl -O https://s3.amazonaws.com/redismodules/rejson/rejson.Linux-x86_64.latest.zip

Install the module to the cluster
$ curl -k -u “<admin-username>:<password>” -F “module=@/<path-to-file>/rejson.Linux-x86_64.latest.zip” http://<your-rp-cluster>:8080/v1/modules

Lastly, create a simple database which enables ReJSON:
$ curl -k -X POST -u “<admin-username>:<password>” -H “Content-Type: application/json” -d ‘{ “name”: “test2”, “port”: 12543, “version”: “4.0”, “memory_size”: 1000000, “type”: “redis”, “module_list”:[“ef96534011d5d9f5aca237aab270ca7d”],
“module_list_args”:[“”,””] }’ http://<your-rp-cluster>:8080/v1/bdbs
Quick start with redis-cli
These examples will use redis-cli as the Redis client to show how easy it is. The first ReJSON command to try out is JSON.SET, which sets a Redis key with a JSON value. All JSON values can be used, for example a string:

Connect to redis using –raw so we can read the json correctly. Otherwise the quotes are \”escaped\” and formatting is not ideal.

$ redis-cli –raw
127.0.0.1:12543>

Add a simple document
127.0.0.1:12543> JSON.SET foo . ‘{“foo” : “bar”}’
OK

Read back the only entity with a get
127.0.0.1:12543> JSON.GET foo
{“foo”:”bar”}

Check what type foo is
127.0.0.1:12543> JSON.TYPE foo .
object

See what type of entity the foo entity is in the foo document.
127.0.0.1:12543> JSON.TYPE foo .foo
string

Now that we have a minimal JSON document. Add some more data to it. The great thing is, we do not need the entire document, we only write what needs to change. Add an entity into the document called test with a integer value of 1.

127.0.0.1:12543> JSON.SET foo .test 1
OK

Next increment that value by 2 and this returns the updated value.
127.0.0.1:12543> JSON.NUMINCRBY foo .test 2
3

Now create a new document, add another document to it, and then add another name/value pair to that sub-document.

127.0.0.1:12543> JSON.SET foo . ‘{“foo”:”bar”}’
OK

Add the test entity with a JSON document

127.0.0.1:12543> JSON.SET foo .test ‘{“test2”:true}’
OK
127.0.0.1:12543> JSON.GET foo
{“foo”:”bar”,”test”:{“test2”:true}}

Add another entity to the test document

127.0.0.1:12543> JSON.SET foo .test.test3 ‘”test”‘
OK
127.0.0.1:12543> JSON.GET foo
{“foo”:”bar”,”test”:{“test2″:true,”test3″:”test”}}