зеркало из https://github.com/github/github-ds.git
Various fixes
This commit is contained in:
Родитель
9f66dd85fc
Коммит
4ae62fc9c0
|
@ -267,7 +267,9 @@ module GitHub
|
|||
def increment(key, amount: 1, expires: nil)
|
||||
validate_key(key)
|
||||
validate_amount(amount) if amount
|
||||
validate_expires(expires) if expries
|
||||
validate_expires(expires) if expires
|
||||
|
||||
expires ||= GitHub::SQL::NULL
|
||||
|
||||
# This query uses a few MySQL "hacks" to ensure that the incrementing
|
||||
# is done atomically and the value is returned. The first trick is done
|
||||
|
@ -420,10 +422,10 @@ module GitHub
|
|||
# # => #<Result value: [2018-04-23 11:34:54 +0200, nil]>
|
||||
#
|
||||
def mttl(keys)
|
||||
validate_keys(key)
|
||||
validate_key_array(keys)
|
||||
|
||||
Result.new {
|
||||
kvs = GitHub::SQL.value(<<-SQL, :keys => keys, :now => now, :connection => connection).to_h
|
||||
kvs = GitHub::SQL.results(<<-SQL, :keys => keys, :now => now, :connection => connection).to_h
|
||||
SELECT expires_at FROM key_values
|
||||
WHERE `key` in :keys AND (expires_at IS NULL OR expires_at > :now)
|
||||
SQL
|
||||
|
|
|
@ -255,6 +255,19 @@ class GitHub::KVTest < Minitest::Test
|
|||
assert_nil @kv.ttl("foo-ttl").value!
|
||||
end
|
||||
|
||||
def test_mttl
|
||||
assert_equal [nil, nil], @kv.mttl(["foo-ttl", "bar-ttl"]).value!
|
||||
|
||||
# the Time.at dance is necessary because MySQL does not support sub-second
|
||||
# precision in DATETIME values
|
||||
expires = Time.at(1.hour.from_now.to_i).utc
|
||||
@kv.set("foo-ttl", "bar", expires: expires)
|
||||
|
||||
puts @kv.mttl(["foo-ttl", "bar-ttl"]).value!
|
||||
|
||||
assert_equal [expires, nil], @kv.mttl(["foo-ttl", "bar-ttl"]).value!
|
||||
end
|
||||
|
||||
def test_type_checks_key
|
||||
assert_raises TypeError do
|
||||
@kv.get(0)
|
||||
|
|
Загрузка…
Ссылка в новой задаче