Class: Jylis::DataType::TREG

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

Overview

A timestamped register.

Defined Under Namespace

Classes: Result

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) ⇒ Jylis::DataType::TREG::Result

Get the latest ‘value` and `timestamp` for the register at `key`.



51
52
53
54
55
# File 'lib/jylis-rb/data_types/treg.rb', line 51

def get(key)
  result = connection.query("TREG", "GET", key)

  Result.parse(result)
end

#set(key, value, timestamp) ⇒ Object

Set a ‘value` and `timestamp` for the register at `key`.

Parameters:

  • timestamp (Integer, String)

    a unix or iso8601 formatted timestamp



60
61
62
63
64
65
66
67
# File 'lib/jylis-rb/data_types/treg.rb', line 60

def set(key, value, timestamp)
  timestamp = Time.parse(timestamp).utc.to_i if timestamp.is_a?(String)
  result    = connection.query("TREG", "SET", key, value, timestamp)

  unless result == "OK"
    raise "Failed: TREG SET #{key} #{value} #{timestamp}"
  end
end