Class: Jylis::DataType::TLOG
- Defined in:
- lib/jylis-rb/data_types/tlog.rb
Overview
A timestamped log.
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#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.
-
#cutoff(key) ⇒ Integer
The current cutoff timestamp of the log at `key`.
-
#get(key, count = nil) ⇒ Jylis::DataType::TLOG::Result
Get the latest `value` and `timestamp` for the register at `key`.
-
#ins(key, value, timestamp) ⇒ Object
Insert a `value`/`timestamp` entry into the log at `key`.
-
#size(key) ⇒ Integer
The number of entries in the log at `key`.
-
#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.
-
#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`.
Methods inherited from Base
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`
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`.
116 117 118 119 120 121 122 123 |
# File 'lib/jylis-rb/data_types/tlog.rb', line 116 def ins(key, value, ) = Time.parse().utc.to_i if .is_a?(String) result = connection.query("TLOG", "INS", key, value, ) unless result == "OK" raise "Failed: TLOG INS #{key} #{value} #{}" end end |
#size(key) ⇒ Integer
Returns 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`.
139 140 141 142 143 144 145 146 |
# File 'lib/jylis-rb/data_types/tlog.rb', line 139 def trimat(key, ) = Time.parse().utc.to_i if .is_a?(String) result = connection.query("TLOG", "TRIMAT", key, ) unless result == "OK" raise "Failed: TLOG TRIMAT #{key} #{}" end end |