Class: Jylis::DataType::PNCOUNT

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

Overview

A positive/negative counter.

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

#dec(key, value) ⇒ Object

Decrease the counter at ‘key` by the amount of `value`.



24
25
26
27
28
29
30
# File 'lib/jylis-rb/data_types/pncount.rb', line 24

def dec(key, value)
  result = connection.query("PNCOUNT", "DEC", key, value)

  unless result == "OK"
    raise "Failed: PNCOUNT DEC #{key} #{value}"
  end
end

#get(key) ⇒ Integer

Get the resulting ‘value` for the counter at `key`.

Returns:

  • (Integer)


10
11
12
# File 'lib/jylis-rb/data_types/pncount.rb', line 10

def get(key)
  connection.query("PNCOUNT", "GET", key)
end

#inc(key, value) ⇒ Object

Increase the counter at ‘key` by the amount of `value`.



15
16
17
18
19
20
21
# File 'lib/jylis-rb/data_types/pncount.rb', line 15

def inc(key, value)
  result = connection.query("PNCOUNT", "INC", key, value)

  unless result == "OK"
    raise "Failed: PNCOUNT INC #{key} #{value}"
  end
end