Class: Jylis::DataType::UJSON

Inherits:
Base
  • Object
show all
Defined in:
lib/jylis-rb/data_types/ujson.rb

Overview

Unordered JSON.

Instance Attribute Summary

Attributes inherited from Base

#connection

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Jylis::DataType::Base

Instance Method Details

#clr(*keys) ⇒ Object

Remove all data stored at or under the given ‘key`.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jylis-rb/data_types/ujson.rb', line 32

def clr(*keys)
  unless keys.count >= 1
    raise ArgumentError.new("Must provide at least one key")
  end

  params = ["UJSON", "CLR"] + keys

  result = connection.query(*params)

  unless result == "OK"
    raise "Failed: UJSON CLR #{params.join(' ')}"
  end
end

#get(*keys) ⇒ Object

Get the JSON representation of the data currently held at ‘key`.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jylis-rb/data_types/ujson.rb', line 12

def get(*keys)
  unless keys.count >= 1
    raise ArgumentError.new("Must provide at least one key")
  end

  params = ["UJSON", "GET"] + keys

  result = connection.query(*params)

  result == "" ? result : Oj.load(result)
end

#ins(*keys, value) ⇒ Object

Insert the given ‘value` as a new element in the set of values stored at `key`.



50
51
52
# File 'lib/jylis-rb/data_types/ujson.rb', line 50

def ins(*args)
  key_value_query(__method__, *args)
end

#rm(*keys, value) ⇒ Object

Remove the specified ‘value` from the set of values stored at `key`.



57
58
59
# File 'lib/jylis-rb/data_types/ujson.rb', line 57

def rm(*args)
  key_value_query(__method__, *args)
end

#set(*keys, value) ⇒ Object

Store the given ‘ujson` data at the given `key`.



27
28
29
# File 'lib/jylis-rb/data_types/ujson.rb', line 27

def set(*args)
  key_value_query(__method__, *args)
end