Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

JSON with Redis server-side Lua

This is an implementation of ReJSON's JSON.SET and JSON.GET commands in pure Redis Lua. The data is stored using Redis' native String data structure.

Yep, that's right, no modules needed.

The implementation consists of two variants: one uses JSON format for storing the data, while the other stores it in MessagePack format.

JSON storage

This variant stores the data in JSON format. It uses (when required) the built-in cjson library for decoding/encoding from/to JSON to/from Lua's native table data type. It is made of the following scripts:

  • json-set-root.lua sets the root to a JSON value. Because this variant stores serialized JSON format, this just calls Redis' SET command.
  • json-get-root.lua gets the JSON value at the root. Similarly, this just calls Redis' GET command to return the serialized JSON value.
  • json-set-path.lua sets the value at a path. To perform the update, the serialized JSON value is decoded, updated and then rendcoded as JSON before being stored.
  • json-get-path.lua gets the value from a path. To perform the read, the serialized JSON value is decoded and then the value at the path is rencoded as JSON before being returned.

MessagePack storage

These scripts use the cmsgpack library to decode/encode the value before/after storing/fetching it in/from Redis. All scripts in this variant are functionally identical to their respective above counterparts but include the required conversions between formats:

You can’t perform that action at this time.