Class: Redis::JSON::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/json/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis_client) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/redis/json/client.rb', line 9

def initialize redis_client
  @redis_client = redis_client
end

Instance Method Details

#arrappend(key, value, *values, path: NOT_PROVIDED, generate_options: {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/redis/json/client.rb', line 17

def arrappend key, value, *values, path: NOT_PROVIDED, generate_options: {}
  value = generate value, **generate_options
  values.map! { |val| generate val, **generate_options }

  if path.eql? NOT_PROVIDED
    call __callee__, key, value, *values
  else
    call __callee__, key, path, value, *values
  end
end

#arrindex(key, value, start = NOT_PROVIDED, stop = NOT_PROVIDED, path:, generate_options: {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/redis/json/client.rb', line 28

def arrindex key, value, start=NOT_PROVIDED, stop=NOT_PROVIDED, path:, generate_options: {}
  value = generate value, **generate_options

  if start.eql? NOT_PROVIDED
    call __callee__, key, path, value
  elsif stop.eql? NOT_PROVIDED
    call __callee__, key, path, value, start
  else
    call __callee__, key, path, value, start, stop
  end
end

#arrinsert(key, index, value, *values, path:, generate_options: {}) ⇒ Object



40
41
42
43
44
45
# File 'lib/redis/json/client.rb', line 40

def arrinsert key, index, value, *values, path:, generate_options: {}
  value = generate value, **generate_options
  values.map! { |val| generate val, **generate_options }

  call __callee__, key, path, index, value, *values
end

#arrlen(key, path: NOT_PROVIDED) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/redis/json/client.rb', line 47

def arrlen key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#arrpop(key, index = NOT_PROVIDED, path: NOT_PROVIDED, parse_options: {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/redis/json/client.rb', line 55

def arrpop key, index=NOT_PROVIDED, path: NOT_PROVIDED, parse_options: {}
  if !index.eql?(NOT_PROVIDED) && path.eql?(NOT_PROVIDED)
    raise ArgumentError,
          'You cannot specify an index unless you also specify a path'
  end

  if path.eql? NOT_PROVIDED
    call(__callee__, key)
      .then do |response|
        parse response, **parse_options if response
      end
  elsif index.eql? NOT_PROVIDED
    call(__callee__, key, path)
      .map do |response|
        parse response, **parse_options if response
      end
  else
    call(__callee__, key, path, index)
      .map do |response|
        parse response, **parse_options if response
      end
  end
end

#arrtrim(key, start, stop, path:) ⇒ Object



79
80
81
# File 'lib/redis/json/client.rb', line 79

def arrtrim key, start, stop, path:
  call __callee__, key, path, start, stop
end

#call(command, *args) ⇒ Object



13
14
15
# File 'lib/redis/json/client.rb', line 13

def call command, *args
  redis_client.call [:"json.#{command}", *args]
end

#clear(key, path: NOT_PROVIDED) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/redis/json/client.rb', line 83

def clear key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#debug_memory(key, path: NOT_PROVIDED) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/redis/json/client.rb', line 91

def debug_memory key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#del(key, path: NOT_PROVIDED) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/redis/json/client.rb', line 99

def del key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#forget(key, path: NOT_PROVIDED) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/redis/json/client.rb', line 107

def forget key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#get(key, *paths, indent: NOT_PROVIDED, newline: NOT_PROVIDED, space: NOT_PROVIDED, parse_options: {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/redis/json/client.rb', line 115

def get key, *paths, indent: NOT_PROVIDED, newline: NOT_PROVIDED, space: NOT_PROVIDED, parse_options: {}
  options = {
    indent:  indent,
    newline: newline,
    space:   space
  }
  options.reject! { |_name, value| value.eql?(NOT_PROVIDED) }
  options.transform_keys!(&:upcase)

  call(__callee__, key, *options.flatten, *paths)
    .then do |response|
      parse response, **parse_options if response
    end
end

#merge(key, value, path:, generate_options: {}) ⇒ Object



130
131
132
133
134
# File 'lib/redis/json/client.rb', line 130

def merge key, value, path:, generate_options: {}
  value = generate value, **generate_options

  call __callee__, key, path, value
end

#mget(key, *keys, path:, parse_options: {}) ⇒ Object



136
137
138
139
140
141
# File 'lib/redis/json/client.rb', line 136

def mget key, *keys, path:, parse_options: {}
  call(__callee__, key, *keys, path)
    .map do |response|
      parse response, **parse_options if response
    end
end

#mset(key, path, value, *rest, generate_options: {}) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/redis/json/client.rb', line 143

def mset key, path, value, *rest, generate_options: {}
  if rest.size % 3 != 0
    raise ArgumentError,
          'mset requires parameters to be in triples <key, path, value>'
  end

  value = generate value, **generate_options
  rest.map!.with_index do |item, index|
    if index % 3 == 2
      generate(item, **generate_options)
    else
      item
    end
  end

  call __callee__, key, path, value, *rest
end

#numincrby(key, value, path:, parse_options: {}) ⇒ Object



161
162
163
164
165
166
# File 'lib/redis/json/client.rb', line 161

def numincrby key, value, path:, parse_options: {}
  call(__callee__, key, path, value)
    .then do |response|
      parse response, **parse_options if response
    end
end

#nummultby(key, value, path:, parse_options: {}) ⇒ Object



168
169
170
171
172
173
# File 'lib/redis/json/client.rb', line 168

def nummultby key, value, path:, parse_options: {}
  call(__callee__, key, path, value)
    .then do |response|
      parse response, **parse_options if response
    end
end

#numpowby(key, value, path:, parse_options: {}) ⇒ Object



175
176
177
178
179
180
# File 'lib/redis/json/client.rb', line 175

def numpowby key, value, path:, parse_options: {}
  call(__callee__, key, path, value)
    .then do |response|
      parse response, **parse_options if response
    end
end

#objkeys(key, path: NOT_PROVIDED) ⇒ Object



182
183
184
185
186
187
188
# File 'lib/redis/json/client.rb', line 182

def objkeys key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#objlen(key, path: NOT_PROVIDED) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/redis/json/client.rb', line 190

def objlen key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#resp(key, path: NOT_PROVIDED) ⇒ Object



198
199
200
201
202
203
204
# File 'lib/redis/json/client.rb', line 198

def resp key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#set(key, value, path:, nx: NOT_PROVIDED, xx: NOT_PROVIDED, generate_options: {}) ⇒ Object

rubocop:disable Naming/MethodParameterName



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/redis/json/client.rb', line 207

def set key, value, path:, nx: NOT_PROVIDED, xx: NOT_PROVIDED, generate_options: {}
  if !nx.eql?(NOT_PROVIDED) && !xx.eql?(NOT_PROVIDED)
    raise ArgumentError,
          'NX and XX are mutually exclusive'
  end

  value = generate value, **generate_options

  if !nx.eql?(NOT_PROVIDED)
    call __callee__, key, path, value, :NX
  elsif !xx.eql?(NOT_PROVIDED)
    call __callee__, key, path, value, :XX
  else
    call __callee__, key, path, value
  end
end

#strappend(key, value, path: NOT_PROVIDED, generate_options: {}) ⇒ Object

rubocop:enable Naming/MethodParameterName



225
226
227
228
229
230
231
232
233
# File 'lib/redis/json/client.rb', line 225

def strappend key, value, path: NOT_PROVIDED, generate_options: {}
  value = generate value, **generate_options

  if path.eql? NOT_PROVIDED
    call __callee__, key, value
  else
    call __callee__, key, path, value
  end
end

#strlen(key, path: NOT_PROVIDED) ⇒ Object



235
236
237
238
239
240
241
# File 'lib/redis/json/client.rb', line 235

def strlen key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end

#toggle(key, path:) ⇒ Object



243
244
245
# File 'lib/redis/json/client.rb', line 243

def toggle key, path:
  call __callee__, key, path
end

#type(key, path: NOT_PROVIDED) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/redis/json/client.rb', line 247

def type key, path: NOT_PROVIDED
  if path.eql? NOT_PROVIDED
    call __callee__, key
  else
    call __callee__, key, path
  end
end