Ferricstore.Commands.Json (ferricstore v0.3.1)

Copy Markdown View Source

Handles Redis JSON commands: JSON.SET, JSON.GET, JSON.DEL, JSON.NUMINCRBY, JSON.TYPE, JSON.STRLEN, JSON.OBJKEYS, JSON.OBJLEN, JSON.ARRAPPEND, JSON.ARRLEN, JSON.TOGGLE, JSON.CLEAR, JSON.MGET.

Starting with Redis 8, JSON is part of Redis Open Source. FerricStore v1 stores JSON as raw bytes in Bitcask using a type tag: :erlang.term_to_binary({:json, json_string}). Every JSON.GET deserializes and evaluates JSONPath. Every JSON.SET reads, applies mutation, writes back.

JSONPath subset (v1)

  • $ -- root
  • $.field -- object field access
  • $.field.subfield -- nested access
  • $[0], $[1] -- array index
  • $.field[0].name -- mixed access

Supported commands

  • JSON.SET key path value [NX|XX] -- set JSON value at path
  • JSON.GET key [path ...] -- get JSON value(s) at path(s)
  • JSON.DEL key [path] -- delete value at path, returns count deleted
  • JSON.NUMINCRBY key path value -- increment number at path
  • JSON.TYPE key [path] -- return JSON type at path
  • JSON.STRLEN key [path] -- return string length at path
  • JSON.OBJKEYS key [path] -- return object keys at path
  • JSON.OBJLEN key [path] -- return number of keys in object at path
  • JSON.ARRAPPEND key path value [value ...] -- append to array at path
  • JSON.ARRLEN key [path] -- return array length at path
  • JSON.TOGGLE key path -- toggle boolean at path
  • JSON.CLEAR key [path] -- clear container or number to zero
  • JSON.MGET key [key ...] path -- get value at path from multiple keys

Summary

Functions

Handles a JSON command.

Functions

handle(cmd, args, store)

@spec handle(binary(), [binary()], map()) :: term()

Handles a JSON command.

Parameters

  • cmd - Uppercased command name (e.g. "JSON.SET", "JSON.GET")
  • args - List of string arguments
  • store - Injected store map with get, put, delete, exists? callbacks

Returns

Plain Elixir term: :ok, nil, integer, string, list, or {:error, message}.