userver: userver/storages/redis/ttl_reply.hpp Source File
Loading...
Searching...
No Matches
ttl_reply.hpp
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <string>
6
7#include <userver/storages/redis/exception.hpp>
8#include <userver/storages/redis/fwd.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace storages::redis {
13
14class TtlReply final {
15public:
16 enum class TtlReplyValue { kKeyDoesNotExist = -2, kKeyHasNoExpiration = -1 };
17
18 static constexpr TtlReplyValue kKeyDoesNotExist = TtlReplyValue::kKeyDoesNotExist;
19 static constexpr TtlReplyValue kKeyHasNoExpiration = TtlReplyValue::kKeyHasNoExpiration;
20
21 explicit TtlReply(int64_t value);
22 TtlReply(TtlReplyValue value);
23
24 static TtlReply Parse(ReplyData&& reply_data, const std::string& request_description = {});
25
26 bool KeyExists() const;
27 bool KeyHasExpiration() const;
28 [[deprecated("Use GetExpire() instead")]] size_t GetExpireSeconds() const { return GetExpire().count(); }
29 std::chrono::seconds GetExpire() const;
30
31private:
32 int64_t value_;
33};
34
35/// Trying to get expiration from a nonexistent or a persistent key
37public:
38 using Exception::Exception;
39};
40
41} // namespace storages::redis
42
43USERVER_NAMESPACE_END