Skip to content

Commit d140814

Browse files
committed
fix and add string api
1 parent 9d3f3c9 commit d140814

File tree

5 files changed

+358
-257
lines changed

5 files changed

+358
-257
lines changed

include/cppredis/client.hpp

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,25 +235,55 @@ namespace cpp_redis {
235235
unit::int_to_string(start),unit::int_to_string(end));
236236
}
237237

238+
int incr(std::string&& key)
239+
{
240+
static_assert(is_sting_, "This API Support String Request");
241+
if (client_ == nullptr || key.empty()) {
242+
return -1;
243+
}
244+
245+
return client_->incr(std::forward<std::string>(key));
246+
}
238247

239-
std::tuple<bool, int> incr(std::string&& key, int increment = 1)
248+
//若key不存在直接创建,并执行增加
249+
int incr_by_increment(std::string&& key, int increment)
240250
{
241251
static_assert(is_sting_, "This API Support String Request");
242252
if (client_ == nullptr || key.empty()) {
243-
return { false,-1 };
253+
return -1;
244254
}
245255

246-
return client_->incr(std::forward<std::string>(key), increment);
256+
return client_->incr_by_increment(std::forward<std::string>(key),unit::int_to_string(increment));
247257
}
248258

249-
std::tuple<bool, int> decr(std::string&& key, int increment = 1)
259+
std::string incr_by_float(std::string&& key,float increment)
250260
{
251261
static_assert(is_sting_, "This API Support String Request");
252-
if (client_ == nullptr || key.empty()) {
253-
return { false,-1 };
262+
if (client_ == nullptr || key.empty()) {
263+
return "";
264+
}
265+
266+
return client_->incr_by_float(std::forward<std::string>(key), unit::float_to_string(increment));
267+
}
268+
269+
int decr(std::string&& key)
270+
{
271+
static_assert(is_sting_, "This API Support String Request");
272+
if (client_ == nullptr || key.empty()) {
273+
return -1;
274+
}
275+
276+
return client_->decr(std::forward<std::string>(key));
277+
}
278+
279+
virtual int decr_increment(std::string&& key,int increment)
280+
{
281+
static_assert(is_sting_, "This API Support String Request");
282+
if (client_ == nullptr || key.empty()) {
283+
return -1 ;
254284
}
255285

256-
return client_->decr(std::forward<std::string>(key), increment);
286+
return client_->decr_increment(std::forward<std::string>(key),unit::int_to_string(increment));
257287
}
258288

259289
std::string get_reflect_value(std::string&& key)
@@ -325,15 +355,16 @@ namespace cpp_redis {
325355
return ptr->multi_set_if_not_set(std::forward<Args>(key_value)...);
326356
}
327357

328-
std::tuple<bool, int> append_value(std::string&& key, std::string&& new_value)
358+
//key不存,会直接创建key
359+
int append_value(std::string&& key, std::string&& append_value)
329360
{
330361
static_assert(is_sting_, "This API Support String Request");
331-
if (client_ == nullptr || key.empty()
332-
|| new_value.empty) {
333-
return { false,-1 };
362+
if (client_ == nullptr || key.empty() || append_value.empty()) {
363+
return 1 ;
334364
}
335365

336-
return client_->append_value(std::forward<std::string>(key), std::forward<std::string>(new_value));
366+
return client_->append_value(std::forward<std::string>(key),
367+
std::forward<std::string>(append_value));
337368
}
338369

339370
std::tuple<bool, int> list_rpush(std::string&& key, std::string&& value)

include/cppredis/client_interface.hpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,29 @@ namespace cpp_redis {
211211
return "";
212212
}
213213

214-
virtual std::tuple<bool, int> incr(std::string&& key, int increment = 1)
214+
virtual int incr_by_increment(std::string&& key,std::string&& increment)
215215
{
216-
return { false,-1 };
216+
return -1 ;
217217
}
218218

219-
virtual std::tuple<bool, int> decr(std::string&& key, int increment = 1)
219+
virtual std::string incr_by_float(std::string&& key, std::string&& increment)
220220
{
221-
return { false,-1 };
221+
return "";
222+
}
223+
224+
virtual int incr(std::string&& key)
225+
{
226+
return -1;
227+
}
228+
229+
virtual int decr(std::string&& key)
230+
{
231+
return -1;
232+
}
233+
234+
virtual int decr_increment(std::string&& key,std::string && increment)
235+
{
236+
return -1;
222237
}
223238

224239
virtual std::string get_reflect_value(std::string&& key)
@@ -237,9 +252,9 @@ namespace cpp_redis {
237252
}
238253

239254
//在指定key追加值
240-
virtual std::tuple<bool, int> append_value(std::string&& key, std::string&& new_value)
255+
virtual int append_value(std::string&& key, std::string&& append_value)
241256
{
242-
return { false,-1 };
257+
return -1;
243258
}
244259

245260
virtual std::tuple<bool, int> list_rpush(std::string&& key, std::string&& value)

0 commit comments

Comments
 (0)