Class: Redis
- Inherits:
-
Object
- Object
- Redis
- Defined in:
- lib/rejson/client.rb
Overview
Extends Redis class to add JSON functions
Instance Method Summary collapse
- #json_arrappend(key, path, json, *args) ⇒ Object
- #json_arrindex(key, path, scalar, start = 0, stop = 0) ⇒ Object
- #json_arrinsert(key, path, index, *args) ⇒ Object
- #json_arrlen(key, path = Rejson::Path.root_path) ⇒ Object
- #json_arrpop(key, path = Rejson::Path.root_path, index = -1)) ⇒ Object
- #json_arrtrim(key, path, start, stop) ⇒ Object
- #json_del(key, path = Rejson::Path.root_path) ⇒ Object (also: #json_forget)
-
#json_get(key, *args) ⇒ Object
rubocop:enable Metrics/AbcSize.
- #json_mget(key, *args) ⇒ Object
- #json_numincrby(key, path, number) ⇒ Object
- #json_nummultby(key, path, number) ⇒ Object
- #json_objkeys(key, path = Rejson::Path.root_path) ⇒ Object
- #json_objlen(key, path = Rejson::Path.root_path) ⇒ Object
- #json_resp(key, path = Rejson::Path.root_path) ⇒ Object
-
#json_set(key, path, data, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #json_strappend(key, string, path = Rejson::Path.root_path) ⇒ Object
- #json_strlen(key, path = Rejson::Path.root_path) ⇒ Object
- #json_type(key, path = Rejson::Path.root_path) ⇒ Object
Instance Method Details
#json_arrappend(key, path, json, *args) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/rejson/client.rb', line 86 def json_arrappend(key, path, json, *args) json_objs = [json_encode(json)] args.each { |arg| json_objs.append(json_encode(arg)) } pieces = [key, str_path(path), json_objs] call_client(:arrappend, pieces).to_i end |
#json_arrindex(key, path, scalar, start = 0, stop = 0) ⇒ Object
93 94 95 96 |
# File 'lib/rejson/client.rb', line 93 def json_arrindex(key, path, scalar, start = 0, stop = 0) pieces = [key, str_path(path), scalar, start, stop] call_client(:arrindex, pieces).to_i end |
#json_arrinsert(key, path, index, *args) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/rejson/client.rb', line 98 def json_arrinsert(key, path, index, *args) json_objs = [] args.each { |arg| json_objs.append(json_encode(arg)) } pieces = [key, str_path(path), index, json_objs] call_client(:arrinsert, pieces).to_i end |
#json_arrlen(key, path = Rejson::Path.root_path) ⇒ Object
105 106 107 108 |
# File 'lib/rejson/client.rb', line 105 def json_arrlen(key, path = Rejson::Path.root_path) pieces = [key, str_path(path)] call_client(:arrlen, pieces).to_i end |
#json_arrpop(key, path = Rejson::Path.root_path, index = -1)) ⇒ Object
110 111 112 113 |
# File 'lib/rejson/client.rb', line 110 def json_arrpop(key, path = Rejson::Path.root_path, index = -1) pieces = [key, str_path(path), index] call_client(:arrpop, pieces).to_s end |
#json_arrtrim(key, path, start, stop) ⇒ Object
115 116 117 118 |
# File 'lib/rejson/client.rb', line 115 def json_arrtrim(key, path, start, stop) pieces = [key, str_path(path), start, stop] call_client(:arrtrim, pieces).to_i end |
#json_del(key, path = Rejson::Path.root_path) ⇒ Object Also known as: json_forget
54 55 56 57 |
# File 'lib/rejson/client.rb', line 54 def json_del(key, path = Rejson::Path.root_path) pieces = [key, str_path(path)] call_client(:del, pieces).to_i end |
#json_get(key, *args) ⇒ Object
rubocop:enable Metrics/AbcSize
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rejson/client.rb', line 27 def json_get(key, *args) pieces = [key] if args.empty? pieces.append(str_path(Rejson::Path.root_path)) else args.each do |arg| pieces.append(str_path(arg)) end end begin json_decode call_client(:get, pieces) rescue TypeError nil end end |
#json_mget(key, *args) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/rejson/client.rb', line 45 def json_mget(key, *args) pieces = [key] raise ArgumentError, "Invalid arguments: Missing path" if args.empty? pieces.append(args) json_bulk_decode call_client(:mget, pieces) end |
#json_numincrby(key, path, number) ⇒ Object
66 67 68 69 |
# File 'lib/rejson/client.rb', line 66 def json_numincrby(key, path, number) pieces = [key, str_path(path), number] call_client(:numincrby, pieces).to_i end |
#json_nummultby(key, path, number) ⇒ Object
71 72 73 74 |
# File 'lib/rejson/client.rb', line 71 def json_nummultby(key, path, number) pieces = [key, str_path(path), number] call_client(:nummultby, pieces).to_i end |
#json_objkeys(key, path = Rejson::Path.root_path) ⇒ Object
120 121 122 123 |
# File 'lib/rejson/client.rb', line 120 def json_objkeys(key, path = Rejson::Path.root_path) pieces = [key, str_path(path)] call_client(:objkeys, pieces).to_a end |
#json_objlen(key, path = Rejson::Path.root_path) ⇒ Object
125 126 127 128 |
# File 'lib/rejson/client.rb', line 125 def json_objlen(key, path = Rejson::Path.root_path) pieces = [key, str_path(path)] call_client(:objlen, pieces).to_i end |
#json_resp(key, path = Rejson::Path.root_path) ⇒ Object
130 131 132 133 |
# File 'lib/rejson/client.rb', line 130 def json_resp(key, path = Rejson::Path.root_path) pieces = [key, str_path(path)] call_client(:resp, pieces) end |
#json_set(key, path, data, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rejson/client.rb', line 9 def json_set(key, path, data, = {}) pieces = [key, str_path(path), json_encode(data)] [:nx] ||= false if .dig(:nx) [:xx] ||= false if .dig(:xx) if [:nx] && [:xx] raise ArgumentError, "nx and xx are mutually exclusive: use one, the other or neither - but not both" elsif [:nx] pieces.append("NX") elsif [:xx] pieces.append("XX") end call_client(:set, pieces) end |
#json_strappend(key, string, path = Rejson::Path.root_path) ⇒ Object
76 77 78 79 |
# File 'lib/rejson/client.rb', line 76 def json_strappend(key, string, path = Rejson::Path.root_path) pieces = [key, str_path(path), json_encode(string)] call_client(:strappend, pieces).to_i end |