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