File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed
Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change 1111#define REDISCPP_VALUE_H_
1212
1313// STD
14+ #include < algorithm>
1415#include < iosfwd>
16+ #include < iterator>
1517#include < memory>
1618#include < string_view>
19+ #include < vector>
1720
1821// REDIS-CPP
1922#include < redis-cpp/detail/config.h>
@@ -142,6 +145,18 @@ class value final
142145 get_value<std::string_view, resp::deserialization::bulk_string>();
143146 }
144147
148+ [[nodiscard]]
149+ auto as_string_array () const
150+ {
151+ return get_array<std::string>();
152+ }
153+
154+ [[nodiscard]]
155+ auto as_integer_array () const
156+ {
157+ return get_array<std::int64_t >();
158+ }
159+
145160 template <typename T>
146161 operator T () const
147162 {
@@ -201,13 +216,36 @@ class value final
201216 [&result] (T const &val)
202217 {
203218 if (is_null (&val))
204- throw std::logic_error (" You can't cast Null to any type." );
219+ throw std::logic_error (" You can't cast Null to a type." );
205220 result = val.get ();
206221 }
207222 }, get ());
208223
209224 return result;
210225 }
226+
227+ template <typename T>
228+ std::vector<T> get_array () const
229+ {
230+ std::vector<T> result;
231+
232+ std::visit (resp::detail::overloaded{
233+ [] (auto const &)
234+ { throw std::bad_cast{}; },
235+ [&result] (resp::deserialization::array const &val)
236+ {
237+ if (is_null (&val))
238+ throw std::logic_error (" You can't cast Null to a type." );
239+ auto const &array = val.get ();
240+ std::transform (std::begin (array), std::end (array),
241+ std::back_inserter (result),
242+ [] (auto const &i) { return value{i}.as <T>(); }
243+ );
244+ }
245+ }, get ());
246+
247+ return result;
248+ }
211249};
212250
213251} // namespace rediscpp
You can’t perform that action at this time.
0 commit comments