class ZSpec::Sink::MemorySink
Public Class Methods
new(state:, expirations:)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 4 def initialize(state:, expirations:) @state = state @expirations = expirations end
Public Instance Methods
brpop(key, timeout: 0)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 37 def brpop(key, timeout: 0) return [], rpop(key) end
brpoplpush(source, destination, timeout: 0)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 41 def brpoplpush(source, destination, timeout: 0) _list, message = brpop(source) lpush(destination, message) message end
decr(key)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 72 def decr(key) @state[key] ||= 0 @state[key] -= 1 end
expire(key, seconds)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 13 def expire(key, seconds) @expirations[key] = seconds end
get(key)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 81 def get(key) @state[key] end
hdel(key, field)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 59 def hdel(key, field) (@state[key] ||= {}).delete(field) end
hget(key, field)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 47 def hget(key, field) (@state[key] ||= {})[field] end
hgetall(key)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 51 def hgetall(key) @state[key] ||= {} end
hincrby(key, field, value)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 63 def hincrby(key, field, value) (@state[key] ||= {})[field] = (hget(key, field) || 0) + 1 end
hset(key, field, value)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 55 def hset(key, field, value) (@state[key] ||= {})[field] = value end
incr(key)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 67 def incr(key) @state[key] ||= 0 @state[key] += 1 end
lpush(key, value)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 17 def lpush(key, value) (@state[key] ||= []).unshift(value) end
lrange(key, start, stop)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 25 def lrange(key, start, stop) (@state[key] ||= [])[start..stop] end
lrem(key, n, value)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 21 def lrem(key, n, value) (@state[key] ||= []).delete(value) end
rpop(key)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 33 def rpop(key) (@state[key] ||= []).pop end
rpush(key, value)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 29 def rpush(key, value) (@state[key] ||= []).push(value) end
set(key, value)
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 77 def set(key, value) @state[key] = value end
time()
click to toggle source
# File lib/zspec/sink/memory_sink.rb, line 9 def time [@state[:time]] end