Class: Jylis::DataType::GCOUNT

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

Overview

A grow-only 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

#get(key) ⇒ Integer

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

Returns:

  • (Integer)


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

def get(key)
  connection.query("GCOUNT", "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/gcount.rb', line 15

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

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