10 #ifndef INCLUDE_FUNAPI_DATABASE_REDIS_H_ 11 #define INCLUDE_FUNAPI_DATABASE_REDIS_H_ 13 #include <boost/bind.hpp> 21 class FUNAPI_DLL_VISIBILITY
Redis {
27 kResultDisconnected = 3
53 std::vector<Ptr<Response> > elements;
56 typedef std::pair<string, double> StrDoublePair;
57 typedef std::vector<StrDoublePair> StrDoublePairList;
58 typedef std::vector<string> StrList;
59 typedef std::pair<string, string> StrPair;
60 typedef std::vector<StrPair> StrPairList;
64 typedef boost::function<void (
69 typedef boost::function<
70 void (
const Result &result,
const size_t &value)> OnSizeReturned;
71 typedef boost::function<
72 void (
const Result &result,
const bool &value)> OnBoolReturned;
73 typedef boost::function<
74 void (
const Result &result,
const int64_t &value)> OnIntReturned;
75 typedef boost::function<
76 void (
const Result &result,
const double &value)> OnDoubleReturned;
77 typedef boost::function<
78 void (
const Result &result,
const string &value)> OnStringReturned;
79 typedef boost::function<
80 void (
const Result &result,
const StrList &values)> OnStrListReturned;
81 typedef boost::function<
82 void (
const Result &result,
83 const StrPairList &str_pairs)> OnStrPairListReturned;
84 typedef boost::function<
85 void (
const Result &result,
86 const bool &value,
const int64_t &value2)> OnBoolIntReturned;
87 typedef boost::function<
88 void (
const Result &result,
89 const StrDoublePairList)> OnStrDoublePairListReturned;
90 typedef boost::function<
91 void (
const std::vector<std::pair<Result, double> > &values)>
92 OnMultipleDoubleReturned;
95 typedef boost::function<void (
const string &channel,
97 typedef boost::function<void (
const string &pattern,
98 const string &channel,
99 const string &message)> OnPSubCallback;
102 typedef boost::function<void (
103 const string &master_name,
105 const string &old_master_address,
110 static Result Del(
const string &key,
112 const string &tag =
"");
113 static Result Del(
const StrList &keys,
115 const string &tag =
"");
116 static Result Exists(
const string &key,
bool *exists,
const string &tag =
"");
117 static Result Expire(
const string &key,
118 const size_t &seconds,
120 const string &tag =
"");
121 static Result PExpire(
const string &key,
122 const size_t &milliseconds,
124 const string &tag =
"");
125 static Result Persist(
const string &key,
127 const string &tag =
"");
128 static Result TTL(
const string &key,
129 int64_t *remaining_ttl,
130 const string &tag =
"");
131 static Result PTTL(
const string &key,
132 int64_t *remaining_ttl,
133 const string &tag =
"");
134 static Result Rename(
const string &key,
135 const string &new_key,
136 const string &tag =
"");
138 static void DelAsync(
const string &key,
139 const OnSizeReturned &callback,
140 const string &tag =
"");
141 static void DelAsync(
const StrList &keys,
142 const OnSizeReturned &callback,
143 const string &tag =
"");
144 static void ExistsAsync(
const string &key,
145 const OnBoolReturned &callback,
146 const string &tag =
"");
147 static void ExpireAsync(
const string &key,
148 const size_t &seconds,
149 const OnBoolReturned &callback,
150 const string &tag =
"");
151 static void PExpireAsync(
const string &key,
152 const size_t &milliseconds,
153 const OnBoolReturned &callback,
154 const string &tag =
"");
155 static void PersistAsync(
const string &key,
156 const OnBoolReturned &callback,
157 const string &tag =
"");
158 static void TTLAsync(
const string &key,
159 const OnIntReturned &callback,
160 const string &tag =
"");
161 static void PTTLAsync(
const string &key,
162 const OnIntReturned &callback,
163 const string &tag =
"");
164 static void RenameAsync(
const string &key,
165 const string &new_key,
166 const OnNonReturned &callback,
167 const string &tag =
"");
170 static Result Append(
const string &key,
172 const string &tag =
"");
173 static Result Incr(
const string &key,
175 const string &tag =
"");
176 static Result IncrBy(
const string &key,
177 const int64_t &increment,
179 const string &tag =
"");
180 static Result IncrByFloat(
const string &key,
181 const double &increment,
183 const string &tag =
"");
184 static Result Decr(
const string &key,
186 const string &tag =
"");
187 static Result DecrBy(
const string &key,
188 const int64_t &decrement,
190 const string &tag =
"");
191 static Result StrLen(
const string &key,
193 const string &tag =
"");
194 static Result Get(
const string &key,
196 const string &tag =
"");
197 static Result MGet(
const StrList &keys,
199 const string &tag =
"");
200 static Result GetRange(
const string &key,
201 const int64_t &start,
204 const string &tag =
"");
205 static Result GetSet(
const string &key,
206 const string &new_value,
208 const string &tag =
"");
209 static Result Set(
const string &key,
211 const string &tag =
"");
212 static Result Set(
const string &key,
214 const CommandOption ex_or_px,
216 const CommandOption nx_or_xx,
217 const string &tag =
"");
218 static Result SetEx(
const string &key,
219 const int64_t &seconds,
221 const string &tag =
"");
222 static Result PSetEx(
const string &key,
223 const int64_t &milliseconds,
225 const string &tag =
"");
226 static Result SetNx(
const string &key,
228 bool *already_exists,
229 const string &tag =
"");
230 static Result MSet(
const StrPairList &key_values,
const string &tag =
"");
231 static Result MSetNx(
const StrPairList &key_values,
232 bool *already_exists,
233 const string &tag =
"");
234 static Result BitCount(
const string &key,
236 const string &tag =
"");
237 static Result BitCount(
const string &key,
238 const int64_t &start,
241 const string &tag =
"");
242 static Result BitOp(
const string &operation,
243 const string &dest_key,
245 size_t *dest_key_size,
246 const string &tag =
"");
247 static Result GetBit(
const string &key,
248 const size_t &offset,
250 const string &tag =
"");
251 static Result SetBit(
const string &key,
252 const size_t &offset,
253 const bool &new_value,
255 const string &tag =
"");
256 static Result Scan(
const string &cursor,
257 const string &pattern,
259 const string &tag =
"");
261 static void AppendAsync(
const string &key,
263 const OnNonReturned &callback,
264 const string &tag =
"");
265 static void IncrAsync(
const string &key,
266 const OnIntReturned &callback,
267 const string &tag =
"");
268 static void IncrByAsync(
const string &key,
269 const int64_t &increment,
270 const OnIntReturned &callback,
271 const string &tag =
"");
272 static void IncrByFloatAsync(
const string &key,
273 const double &increment,
274 const OnDoubleReturned &callback,
275 const string &tag =
"");
276 static void DecrAsync(
const string &key,
277 const OnIntReturned &callback,
278 const string &tag =
"");
279 static void DecrByAsync(
const string &key,
280 const int64_t &decrement,
281 const OnIntReturned &callback,
282 const string &tag =
"");
283 static void StrLenAsync(
const string &key,
284 const OnSizeReturned &callback,
285 const string &tag =
"");
286 static void GetAsync(
const string &key,
287 const OnStringReturned &callback,
288 const string &tag =
"");
289 static void MGetAsync(
const StrList &keys,
290 const OnStrListReturned &callback,
291 const string &tag =
"");
292 static void GetRangeAsync(
const string &key,
293 const int64_t &start,
295 const OnStringReturned &callback,
296 const string &tag =
"");
297 static void GetSetAsync(
const string &key,
298 const string &new_value,
299 const OnStringReturned &callback,
300 const string &tag =
"");
301 static void SetAsync(
const string &key,
303 const OnNonReturned &callback,
304 const string &tag =
"");
305 static void SetAsync(
const string &key,
307 const CommandOption ex_or_px,
309 const CommandOption nx_or_xx,
310 const OnNonReturned &callback,
311 const string &tag =
"");
312 static void SetExAsync(
const string &key,
313 const int64_t &seconds,
315 const OnNonReturned &callback,
316 const string &tag =
"");
317 static void PSetExAsync(
const string &key,
318 const int64_t &milliseconds,
320 const OnNonReturned &callback,
321 const string &tag =
"");
322 static void SetNxAsync(
const string &key,
324 const OnBoolReturned &callback,
325 const string &tag =
"");
326 static void MSetAsync(
const StrPairList &key_values,
327 const OnNonReturned &callback,
328 const string &tag =
"");
329 static void MSetNxAsync(
const StrPairList &key_values,
330 const OnBoolReturned &callback,
331 const string &tag =
"");
332 static void BitCountAsync(
const string &key,
333 const OnSizeReturned &callback,
334 const string &tag =
"");
335 static void BitCountAsync(
const string &key,
336 const int64_t &start,
338 const OnSizeReturned &callback,
339 const string &tag =
"");
340 static void BitOpAsync(
const string &operation,
341 const string &dest_key,
343 const OnSizeReturned &callback,
344 const string &tag =
"");
345 static void GetBitAsync(
const string &key,
346 const size_t &offset,
347 const OnBoolReturned &callback,
348 const string &tag =
"");
349 static void SetBitAsync(
const string &key,
350 const size_t &offset,
351 const bool &new_value,
352 const OnBoolReturned &callback,
353 const string &tag =
"");
354 static void ScanAsync(
const string &cursor,
355 const string &pattern,
356 const OnStrListReturned &callback,
357 const string &tag =
"");
360 static Result HExists(
const string &key,
363 const string &tag =
"");
364 static Result HKeys(
const string &key,
366 const string &tag =
"");
367 static Result HVals(
const string &key,
369 const string &tag =
"");
370 static Result HLen(
const string &key,
372 const string &tag =
"");
373 static Result HIncrBy(
const string &key,
375 const int64_t &increment,
377 const string &tag =
"");
378 static Result HIncrByFloat(
const string &key,
380 const double &increment,
382 const string &tag =
"");
383 static Result HDel(
const string &key,
386 const string &tag =
"");
387 static Result HDel(
const string &key,
388 const StrList &fields,
390 const string &tag =
"");
391 static Result HGet(
const string &key,
394 const string &tag =
"");
395 static Result HGetAll(
const string &key,
396 StrPairList *field_values,
397 const string &tag =
"");
398 static Result HMGet(
const string &key,
399 const StrList &fields,
401 const string &tag =
"");
402 static Result HSet(
const string &key,
405 const string &tag =
"");
406 static Result HSetNx(
const string &key,
409 bool *already_exists,
410 const string &tag =
"");
411 static Result HMSet(
const string &key,
412 const StrPairList &field_values,
413 const string &tag =
"");
415 static void HExistsAsync(
const string &key,
417 const OnBoolReturned &callback,
418 const string &tag =
"");
419 static void HKeysAsync(
const string &key,
420 const OnStrListReturned &callback,
421 const string &tag =
"");
422 static void HValsAsync(
const string &key,
423 const OnStrListReturned &callback,
424 const string &tag =
"");
425 static void HLenAsync(
const string &key,
426 const OnSizeReturned &callback,
427 const string &tag =
"");
428 static void HIncrByAsync(
const string &key,
430 const int64_t &increment,
431 const OnIntReturned &callback,
432 const string &tag =
"");
433 static void HIncrByFloatAsync(
const string &key,
435 const double &increment,
436 const OnDoubleReturned &callback,
437 const string &tag =
"");
438 static void HDelAsync(
const string &key,
440 const OnSizeReturned &callback,
441 const string &tag =
"");
442 static void HDelAsync(
const string &key,
443 const StrList &fields,
444 const OnSizeReturned &callback,
445 const string &tag =
"");
446 static void HGetAsync(
const string &key,
448 const OnStringReturned &callback,
449 const string &tag =
"");
450 static void HGetAllAsync(
const string &key,
451 const OnStrPairListReturned &callback,
452 const string &tag =
"");
453 static void HMGetAsync(
const string &key,
454 const StrList &fields,
455 const OnStrListReturned &callback,
456 const string &tag =
"");
457 static void HSetAsync(
const string &key,
460 const OnNonReturned &callback,
461 const string &tag =
"");
462 static void HSetNxAsync(
const string &key,
465 const OnBoolReturned &callback,
466 const string &tag =
"");
467 static void HMSetAsync(
const string &key,
468 const StrPairList &field_values,
469 const OnNonReturned &callback,
470 const string &tag =
"");
473 static Result LLen(
const string &key,
475 const string &tag =
"");
476 static Result LIndex(
const string &key,
477 const int64_t &index,
479 const string &tag =
"");
480 static Result LRange(
const string &key,
481 const int64_t &start,
484 const string &tag =
"");
485 static Result LRem(
const string &key,
486 const int64_t &count,
489 const string &tag =
"");
490 static Result LTrim(
const string &key,
491 const int64_t &start,
493 const string &tag =
"");
494 static Result LPush(
const string &key,
496 size_t *total_length,
497 const string &tag =
"");
498 static Result LPush(
const string &key,
499 const StrList &values,
500 size_t *total_length,
501 const string &tag =
"");
502 static Result RPush(
const string &key,
504 size_t *total_length,
505 const string &tag =
"");
506 static Result RPush(
const string &key,
507 const StrList &values,
508 size_t *total_length,
509 const string &tag =
"");
510 static Result LPop(
const string &key,
512 const string &tag =
"");
513 static Result RPop(
const string &key,
515 const string &tag =
"");
516 static Result LInsert(
const string &key,
520 bool *key_or_pivot_not_found,
521 int64_t *total_length,
522 const string &tag =
"");
523 static Result LSet(
const string &key,
524 const int64_t &index,
526 const string &tag =
"");
528 static void LLenAsync(
const string &key,
529 const OnSizeReturned &callback,
530 const string &tag =
"");
531 static void LIndexAsync(
const string &key,
532 const int64_t &index,
533 const OnStringReturned &callback,
534 const string &tag =
"");
535 static void LRangeAsync(
const string &key,
536 const int64_t &start,
538 const OnStrListReturned &callback,
539 const string &tag =
"");
540 static void LRemAsync(
const string &key,
541 const int64_t &count,
543 const OnSizeReturned &callback,
544 const string &tag =
"");
545 static void LTrimAsync(
const string &key,
546 const int64_t &start,
548 const OnNonReturned &callback,
549 const string &tag =
"");
550 static void LPushAsync(
const string &key,
552 const OnSizeReturned &callback,
553 const string &tag =
"");
554 static void LPushAsync(
const string &key,
555 const StrList &values,
556 const OnSizeReturned &callback,
557 const string &tag =
"");
558 static void RPushAsync(
const string &key,
560 const OnSizeReturned &callback,
561 const string &tag =
"");
562 static void RPushAsync(
const string &key,
563 const StrList &values,
564 const OnSizeReturned &callback,
565 const string &tag =
"");
566 static void LPopAsync(
const string &key,
567 const OnStringReturned &callback,
568 const string &tag =
"");
569 static void RPopAsync(
const string &key,
570 const OnStringReturned &callback,
571 const string &tag =
"");
572 static void LInsertAsync(
const string &key,
576 const OnBoolIntReturned &callback,
577 const string &tag =
"");
578 static void LSetAsync(
const string &key,
579 const int64_t &index,
581 const OnNonReturned &callback,
582 const string &tag =
"");
585 static Result SCard(
const string &key,
587 const string &tag =
"");
588 static Result SIsMember(
const string &key,
589 const string &member,
591 const string &tag =
"");
592 static Result SMembers(
const string &key,
594 const string &tag =
"");
595 static Result SRandMember(
const string &key,
597 const string &tag =
"");
598 static Result SRandMember(
const string &key,
599 const int64_t &count,
601 const string &tag =
"");
602 static Result SDiff(
const StrList &keys,
604 const string &tag =
"");
605 static Result SDiffStore(
const string &destination,
607 size_t *destination_size,
608 const string &tag =
"");
609 static Result SInter(
const StrList &keys,
611 const string &tag =
"");
612 static Result SInterStore(
const string &destination,
614 size_t *destination_size,
615 const string &tag =
"");
616 static Result SUnion(
const StrList &keys,
618 const string &tag =
"");
619 static Result SUnionStore(
const string &destination,
621 size_t *destination_size,
622 const string &tag =
"");
623 static Result SAdd(
const string &key,
624 const string &member,
626 const string &tag =
"");
627 static Result SAdd(
const string &key,
628 const StrList &members,
630 const string &tag =
"");
631 static Result SPop(
const string &key,
633 const string &tag =
"");
634 static Result SRem(
const string &key,
635 const string &member,
637 const string &tag =
"");
638 static Result SRem(
const string &key,
639 const StrList &members,
641 const string &tag =
"");
642 static Result SMove(
const string &source,
643 const string &destination,
644 const string &member,
646 const string &tag =
"");
648 static void SCardAsync(
const string &key,
649 const OnSizeReturned &callback,
650 const string &tag =
"");
651 static void SIsMemberAsync(
const string &key,
652 const string &member,
653 const OnBoolReturned &callback,
654 const string &tag =
"");
655 static void SMembersAsync(
const string &key,
656 const OnStrListReturned &callback,
657 const string &tag =
"");
658 static void SRandMemberAsync(
const string &key,
659 const OnStringReturned &callback,
660 const string &tag =
"");
661 static void SRandMemberAsync(
const string &key,
662 const int64_t &count,
663 const OnStrListReturned &callback,
664 const string &tag =
"");
665 static void SDiffAsync(
const StrList &keys,
666 const OnStrListReturned &callback,
667 const string &tag =
"");
668 static void SDiffStoreAsync(
const string &destination,
670 const OnSizeReturned &callback,
671 const string &tag =
"");
672 static void SInterAsync(
const StrList &keys,
673 const OnStrListReturned &callback,
674 const string &tag =
"");
675 static void SInterStoreAsync(
const string &destination,
677 const OnSizeReturned &callback,
678 const string &tag =
"");
679 static void SUnionAsync(
const StrList &keys,
680 const OnStrListReturned &callback,
681 const string &tag =
"");
682 static void SUnionStoreAsync(
const string &destination,
684 const OnSizeReturned &callback,
685 const string &tag =
"");
686 static void SAddAsync(
const string &key,
687 const string &member,
688 const OnSizeReturned &callback,
689 const string &tag =
"");
690 static void SAddAsync(
const string &key,
691 const StrList &members,
692 const OnSizeReturned &callback,
693 const string &tag =
"");
694 static void SPopAsync(
const string &key,
695 const OnStringReturned &callback,
696 const string &tag =
"");
697 static void SRemAsync(
const string &key,
698 const string &member,
699 const OnSizeReturned &callback,
700 const string &tag =
"");
701 static void SRemAsync(
const string &key,
702 const StrList &members,
703 const OnSizeReturned &callback,
704 const string &tag =
"");
705 static void SMoveAsync(
const string &source,
706 const string &destination,
707 const string &member,
708 const OnBoolReturned &callback,
709 const string &tag =
"");
712 static Result ZCard(
const string &key,
714 const string &tag =
"");
715 static Result ZCount(
const string &key,
719 const string &tag =
"");
720 static Result ZScore(
const string &key,
721 const string &member,
723 const string &tag =
"");
724 static Result ZRevRank(
const string &key,
725 const string &member,
727 const string &tag =
"");
728 static Result ZRevRange(
const string &key,
729 const int64_t &start,
731 const bool &withscores,
732 StrDoublePairList *member_scores,
733 const string &tag =
"");
734 static Result ZAdd(
const string &key,
736 const string &member,
737 const string &tag =
"");
738 static Result ZIncrBy(
const string &key,
739 const double &increment,
740 const string &member,
742 const string &tag =
"");
743 static Result ZRem(
const string &key,
744 const string &member,
746 const string &tag =
"");
747 static Result ZRem(
const string &key,
748 const StrList &members,
750 const string &tag =
"");
752 static void ZCardAsync(
const string &key,
753 const OnSizeReturned &callback,
754 const string &tag =
"");
755 static void ZCountAsync(
const string &key,
758 const OnSizeReturned &callback,
759 const string &tag =
"");
760 static void ZScoreAsync(
const string &key,
761 const string &member,
762 const OnDoubleReturned &callback,
763 const string &tag =
"");
764 static void ZScoreExtAsync(
const string &key,
765 const StrList &members,
766 const OnMultipleDoubleReturned &callback,
767 const string &tag =
"");
768 static void ZRevRankAsync(
const string &key,
769 const string &member,
770 const OnSizeReturned &callback,
771 const string &tag =
"");
772 static void ZRevRangeAsync(
const string &key,
773 const int64_t &start,
775 const bool &withscores,
776 const OnStrDoublePairListReturned &callback,
777 const string &tag =
"");
778 static void ZAddAsync(
const string &key,
780 const string &member,
781 const OnNonReturned &callback,
782 const string &tag =
"");
783 static void ZIncrByAsync(
const string &key,
784 const double &increment,
785 const string &member,
786 const OnDoubleReturned &callback,
787 const string &tag =
"");
788 static void ZRemAsync(
const string &key,
789 const string &member,
790 const OnSizeReturned &callback,
791 const string &tag =
"");
792 static void ZRemAsync(
const string &key,
793 const StrList &members,
794 const OnSizeReturned &callback,
795 const string &tag =
"");
801 static Result Publish(
const string &channel,
802 const string &message,
803 size_t *received_client_count,
804 const string &tag =
"");
805 static Result Unsubscribe(
const string &tag =
"");
806 static Result Unsubscribe(
const string &channel,
const string &tag =
"");
807 static Result Unsubscribe(
const StrList &channels,
const string &tag =
"");
808 static Result PUnsubscribe(
const string &tag =
"");
809 static Result PUnsubscribe(
const string &pattern,
const string &tag =
"");
810 static Result PUnsubscribe(
const StrList &patterns,
const string &tag =
"");
812 static void PublishAsync(
const string &channel,
813 const string &message,
814 const OnSizeReturned &callback,
815 const string &tag =
"");
816 static void SubscribeAsync(
const string &channel,
817 const OnSubCallback &callback,
818 const string &tag =
"");
819 static void SubscribeAsync(
const StrList &channels,
820 const OnSubCallback &callback,
821 const string &tag =
"");
822 static void PSubscribeAsync(
const string &pattern,
823 const OnPSubCallback &callback,
824 const string &tag =
"");
825 static void PSubscribeAsync(
const StrList &patterns,
826 const OnPSubCallback &callback,
827 const string &tag =
"");
828 static void UnsubscribeAsync(
const OnNonReturned &callback,
829 const string &tag =
"");
830 static void UnsubscribeAsync(
const string &channel,
831 const OnNonReturned &callback,
832 const string &tag =
"");
833 static void UnsubscribeAsync(
const StrList &channels,
834 const OnNonReturned &callback,
835 const string &tag =
"");
836 static void PUnsubscribeAsync(
const OnNonReturned &callback,
837 const string &tag =
"");
838 static void PUnsubscribeAsync(
const string &pattern,
839 const OnNonReturned &callback,
840 const string &tag =
"");
841 static void PUnsubscribeAsync(
const StrList &patterns,
842 const OnNonReturned &callback,
843 const string &tag =
"");
847 static Result Multi(
const string &tag =
"");
848 static Ptr<Response> Exec(
const string &tag =
"");
849 static Result Discard(
const string &tag =
"");
852 static void SubscribeSentinelSwitchMasterChannelAsync(
853 const OnSentinelMasterSwitched &cb,
854 const string &tag =
"");
857 static Ptr<Response> ExecuteCommand(
const string &command_name,
858 const std::vector<string> *arguments,
859 const string &tag =
"");
860 static void ExecuteCommandAsync(
const string &command_name,
861 const std::vector<string> *arguments,
862 const OnResponseReturned &callback,
863 const string &tag =
"");
868 #endif // INCLUDE_FUNAPI_DATABASE_REDIS_H_
boost::function< void(const Result &result)> OnNonReturned
for redis command functions
Definition: redis.h:68
boost::function< void(const string &master_name, const string &old_master_address, const string &new_master_address)> OnSentinelMasterSwitched
for Redis Sentinel
Definition: redis.h:107
boost::function< void(const Ptr< Response > &response)> OnResponseReturned
Callbacks for redis async commands for CommandAsync function.
Definition: redis.h:65
boost::function< void(const string &channel, const string &message)> OnSubCallback
for (p)subscribe redis commands
Definition: redis.h:96
#define DECLARE_CLASS_PTR(CLS)
Utility macro to forward-declare smart pointer types for a given class.
Definition: types.h:89