Skip to content

GET SET

Pavan Vachhani edited this page Jun 26, 2020 · 1 revision

SET

Parameters:

  1. key: Key of JSON document
  2. path: Path
  3. data: JSON data
# Allows all datatypes as shown
datatypes_json = {:string=>"string value", :nil=>nil, :bool=>true, :int=>42, :num=>4.2, :arr=>[42, nil, -1.2, false, ["sub", "array"], {:subdict=>true}], :dict=>{:a=>1, :b=>"2", :c=>nil}} 
client.json_set "foo", Rejson::Path.root_path, datatypes_json
# => "OK"

client.json_set "foo", Rejson::Path.new(".dict.a"), 5
# => "OK"

# Pass nx flag to replace if not existing
client.json_set "foo", Rejson::Path.new(".dict.a"), 6, nx: true
# => nil (As 5 exists, returns nil)

# Pass xx to replace if existing
client.json_set "foo", Rejson::Path.new(".dict.a"), 6, xx: true
# => "OK"

GET

Parameters

  1. key: Key of JSON Document
  2. path: Path Defaults to root path if not defined
# Defaults to root path

client.json_get "foo"
# => {"string"=>"string value", "nil"=>nil, "bool"=>true, "int"=>42, "num"=>4.2, "arr"=>[42, nil, -1.2, false, ["sub", "array"], {"subdict"=>true}], "dict"=>{"a"=>5, "b"=>"2", "c"=>nil}}

# Pass a path
client.json_get "foo", ".dict.a"
# => 5
Clone this wiki locally