userver: userver/storages/redis/ttl_reply.hpp Source File
Loading...
Searching...
No Matches
ttl_reply.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/redis/ttl_reply.hpp
4/// @brief Redis TTL reply value and exception for invalid TTL queries
5
6#include <chrono>
7#include <cstdint>
8#include <string>
9
10#include <userver/storages/redis/exception.hpp>
11#include <userver/storages/redis/fwd.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace storages::redis {
16
17/// @brief Parsed TTL/PTTL reply (expiration or missing/persistent key)
18class TtlReply final {
19public:
20 enum class TtlReplyValue { kKeyDoesNotExist = -2, kKeyHasNoExpiration = -1 };
21
22 static constexpr TtlReplyValue kKeyDoesNotExist = TtlReplyValue::kKeyDoesNotExist;
23 static constexpr TtlReplyValue kKeyHasNoExpiration = TtlReplyValue::kKeyHasNoExpiration;
24
25 explicit TtlReply(int64_t value);
26 TtlReply(TtlReplyValue value);
27
28 static TtlReply Parse(ReplyData&& reply_data, const std::string& request_description = {});
29
30 bool KeyExists() const;
31 bool KeyHasExpiration() const;
32 [[deprecated("Use GetExpire() instead")]] size_t GetExpireSeconds() const { return GetExpire().count(); }
33 std::chrono::seconds GetExpire() const;
34
35private:
36 int64_t value_;
37};
38
39/// @brief Thrown when reading TTL for a missing or persistent key
41public:
42 using Exception::Exception;
43};
44
45} // namespace storages::redis
46
47USERVER_NAMESPACE_END