class Jylis::DataType::TLOG

A timestamped log.

@see jemc.github.io/jylis/docs/types/tlog/

Public Instance Methods

clr(key) click to toggle source

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.

# 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) click to toggle source

@return [Integer] the current cutoff timestamp of the log at `key`

# File lib/jylis-rb/data_types/tlog.rb, line 131
def cutoff(key)
  connection.query("TLOG", "CUTOFF", key)
end
get(key, count = nil) click to toggle source

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

@return [Jylis::DataType::TLOG::Result]

# 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) click to toggle source

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

@param timestamp [Integer, String] a unix or iso8601 formatted timestamp

# 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) click to toggle source

@return [Integer] the number of entries in the log at `key`

# File lib/jylis-rb/data_types/tlog.rb, line 126
def size(key)
  connection.query("TLOG", "SIZE", key)
end
trim(key, count) click to toggle source

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.

# 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) click to toggle source

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

@param timestamp [Integer, String] a unix or iso8601 formatted timestamp

# 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