-
Notifications
You must be signed in to change notification settings - Fork 15
GET SET
Pavan Vachhani edited this page Jun 26, 2020
·
1 revision
- key: Key of JSON document
- path: Path
- 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"
- key: Key of JSON Document
- 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