Class: Jylis::DataType::TLOG

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

Overview

A timestamped log.

Defined Under Namespace

Classes: Result, Row

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(key) ⇒ Object

Raise the cutoff timestamp to be the timestamp of the latest entry plus one, such that all local entries in the log will be discarded due to having timestamps earlier than the cutoff timestamp.



164
165
166
167
168
169
170
# File 'lib/jylis-rb/data_types/tlog.rb', line 164

def clr(key)
  result = connection.query("TLOG", "CLR", key)

  unless result == "OK"
    raise "Failed: TLOG CLR #{key}"
  end
end

#cutoff(key) ⇒ Integer

Returns the current cutoff timestamp of the log at `key`

Returns:

  • (Integer)

    the current cutoff timestamp of the log at `key`



131
132
133
# File 'lib/jylis-rb/data_types/tlog.rb', line 131

def cutoff(key)
  connection.query("TLOG", "CUTOFF", key)
end

#get(key, count = nil) ⇒ Jylis::DataType::TLOG::Result

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



94
95
96
97
98
99
100
101
102
# File 'lib/jylis-rb/data_types/tlog.rb', line 94

def get(key, count = nil)
  params = ["TLOG", "GET", key]

  params.push(count) if count

  result = connection.query(*params)

  Result.parse(result)
end

#ins(key, value, timestamp) ⇒ Object

Insert a `value`/`timestamp` entry into the log at `key`.

Parameters:

  • timestamp (Integer, String)

    a unix or iso8601 formatted timestamp



116
117
118
119
120
121
122
123
# File 'lib/jylis-rb/data_types/tlog.rb', line 116

def ins(key, value, timestamp)
  timestamp = Time.parse(timestamp).utc.to_i if timestamp.is_a?(String)
  result    = connection.query("TLOG", "INS", key, value, timestamp)

  unless result == "OK"
    raise "Failed: TLOG INS #{key} #{value} #{timestamp}"
  end
end

#size(key) ⇒ Integer

Returns the number of entries in the log at `key`

Returns:

  • (Integer)

    the number of entries in the log at `key`



126
127
128
# File 'lib/jylis-rb/data_types/tlog.rb', line 126

def size(key)
  connection.query("TLOG", "SIZE", key)
end

#trim(key, count) ⇒ Object

Raise the cutoff timestamp of the log to retain at least `count` entries, by setting the cutoff timestamp to the timestamp of the entry at index `count - 1` in the log. Any entries with an earlier timestamp than the entry at that index will be discarded. If `count` is zero, this is the same as calling #clr.



153
154
155
156
157
158
159
# File 'lib/jylis-rb/data_types/tlog.rb', line 153

def trim(key, count)
  result = connection.query("TLOG", "TRIM", key, count)

  unless result == "OK"
    raise "Failed: TLOG TRIM #{key} #{count}"
  end
end

#trimat(key, timestamp) ⇒ Object

Raise the cutoff timestamp of the log, causing any entries to be discarded whose timestamp is earlier than the newly given `timestamp`.

Parameters:

  • timestamp (Integer, String)

    a unix or iso8601 formatted timestamp



139
140
141
142
143
144
145
146
# File 'lib/jylis-rb/data_types/tlog.rb', line 139

def trimat(key, timestamp)
  timestamp = Time.parse(timestamp).utc.to_i if timestamp.is_a?(String)
  result    = connection.query("TLOG", "TRIMAT", key, timestamp)

  unless result == "OK"
    raise "Failed: TLOG TRIMAT #{key} #{timestamp}"
  end
end