Documentation

Redis Enterprise Software - Operations and Administration Guide

open all | close all

ReJSON Quick Start Tutorial

For this quick start, you will need the following:

Add ReJSON module to Redis Enterprise Software cluster

Download the Module

To download this module, go to the Redis Enterprise downloads page. The module should be downloaded to wherever you use a browser to access the Redis Enterprise Software web UI.

Add Module to UI

  1. Log into the Redis Enterprise Software web UI
  2. Navigate to the settings -> redise modules
  3. Click on Add Module button and navigate to where you downloaded the module package
  4. Click on the Upload button and notice the name and version

Create a new database that uses the Module

  1. Navigate to databases tab
  2. Click on the + sign, if necessary, then create database
  3. On the create database screen, check the box for Redis Modules and select the module you want to use for this database.
  4. Click Show advanced options and put 12543 for the port.
  5. Click the activate button

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 -p 12543
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"}}