iFun Engine API  1.0.0-b6053
Great Technology for Great Games
redis_client.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 //
7 
10 #ifndef INCLUDE_FUNAPI_DATABASE_REDIS_CLIENT_H_
11 #define INCLUDE_FUNAPI_DATABASE_REDIS_CLIENT_H_
12 
13 #include <funapi/common/json.h>
14 #include <funapi/types.h>
15 
16 #include <string>
17 #include <vector>
18 
19 
20 namespace fun {
21 
22 class FUNAPI_DLL_VISIBILITY RedisClient {
23  public:
24  struct FUNAPI_DLL_VISIBILITY Result {
25  enum Type {
26  kError = 0,
27  kSuccess = 1,
28  kNil = 2,
29  };
30 
31  Result();
32 
33  Type type;
34  int error_code;
35  string error_desc;
36  };
37 
38  struct FUNAPI_DLL_VISIBILITY Reply {
39  enum Type {
40  kString = 1,
41  kArray = 2,
42  kInteger = 3,
43  kNil = 4,
44  kStatus = 5,
45  kError = 6
46  };
47 
49 
50  Type type;
51  int64_t integer;
52  string str;
53  std::vector<Ptr<Reply> > elements;
54  };
55 
56  enum CommandOption {
57  kNone = 0,
58 
59  kEX,
60  kPX,
61  kNX,
62  kXX,
63 
64  kAND,
65  kOR,
66  kXOR,
67  kNOT,
68 
69  kBEFORE,
70  kAFTER
71  };
72 
73  typedef std::vector<string> StringList;
74  typedef std::pair<string, string> StringPair;
75  typedef std::vector<StringPair> StringPairList;
76  typedef std::pair<string, double> StringDoublePair;
77  typedef std::vector<StringDoublePair> StringDoublePairList;
78 
79  typedef function<void(const Result &, const Ptr<Reply> &)> Callback;
80  typedef function<void(const Result &, int64_t)> IntegerCallback;
81  typedef function<void(const Result &, double)> DoubleCallback;
82  typedef function<void(const Result &, const string &)> StringCallback;
83  typedef function<void(const Result &, const StringList &)> StringListCallback;
84  typedef function<void(const Result &,
85  const StringPairList &)> StringPairListCallback;
86  typedef function<
87  void(const Result &,
88  const StringDoublePairList &)> StringDoublePairListCallback;
89 
90  typedef function<void(const string &/*channel*/,
91  const string &/*message*/)> SubCallback;
92  typedef function<void(const string &/*pattern*/,
93  const string &/*channel*/,
94  const string &/*message*/)> PSubCallback;
95 
97  typedef boost::function<
98  void (const string &/*master_name*/,
99  const string &/*old_master_address*/,
100  const string &/*new_master_address*/)>
102 
103  typedef function<void(size_t /*connection_index*/)> DisconnectCallback;
104 
105  typedef Uuid SerializationTag;
106  static const SerializationTag kDefaultSerializationTag;
107 
108  static Ptr<RedisClient> Create(const string &server_ip,
109  int server_port,
110  const string &auth_pass,
111  size_t connection_count,
112  bool invoke_as_event = true,
113  size_t database = 0);
114 
115  static Ptr<RedisClient> Create(const string &master_name,
116  const std::vector<string> &sentinel_addresses,
117  const string &auth_pass,
118  size_t connection_count,
119  bool invoke_as_event = true,
120  size_t database = 0);
121 
122  void Initialize();
123  void Finalize(bool immediately = false);
124 
125  size_t GetConnectedConnectionCount() const;
126 
127  void SetProfiling(bool is_on);
128  void DumpProfilingResult(Json *out);
129 
130  void RegisterDisconnectCallback(const DisconnectCallback &callback);
131 
133  void SetSentinelMasterSwitchedCallback(
134  const SentinelMasterSwitchedCallback &callback);
135 
136  bool invoke_as_event() const;
137 
139  void Del(const string &key, const IntegerCallback &callback,
140  const SerializationTag &tag = kDefaultSerializationTag);
141  void Del(const StringList &keys, const IntegerCallback &callback,
142  const SerializationTag &tag = kDefaultSerializationTag);
143  void Exists(const string &key, const IntegerCallback &callback,
144  const SerializationTag &tag = kDefaultSerializationTag);
145  void Expire(const string &key, uint64_t seconds,
146  const IntegerCallback &callback,
147  const SerializationTag &tag = kDefaultSerializationTag);
148  void PExpire(const string &key, uint64_t milliseconds,
149  const IntegerCallback &callback,
150  const SerializationTag &tag = kDefaultSerializationTag);
151  void Persist(const string &key, const IntegerCallback &callback,
152  const SerializationTag &tag = kDefaultSerializationTag);
153  void TTL(const string &key, const IntegerCallback &callback,
154  const SerializationTag &tag = kDefaultSerializationTag);
155  void PTTL(const string &key, const IntegerCallback &callback,
156  const SerializationTag &tag = kDefaultSerializationTag);
157  void Rename(const string &key, const string &new_key,
158  const StringCallback &callback,
159  const SerializationTag &tag = kDefaultSerializationTag);
160 
161  Result DelSync(const string &key, int64_t *out);
162  Result DelSync(const StringList &keys, int64_t *out);
163  Result ExistsSync(const string &key, int64_t *out);
164  Result ExpireSync(const string &key, uint64_t seconds, int64_t *out);
165  Result PExpireSync(const string &key, uint64_t milliseconds, int64_t *out);
166  Result PersistSync(const string &key, int64_t *out);
167  Result TTLSync(const string &key, int64_t *out);
168  Result PTTLSync(const string &key, int64_t *out);
169  Result RenameSync(const string &key, const string &new_key, string *out);
170 
172  void Append(const string &key, const string &value,
173  const IntegerCallback &callback,
174  const SerializationTag &tag = kDefaultSerializationTag);
175  void Incr(const string &key, const IntegerCallback &callback,
176  const SerializationTag &tag = kDefaultSerializationTag);
177  void IncrBy(const string &key, int64_t increment,
178  const IntegerCallback &callback,
179  const SerializationTag &tag = kDefaultSerializationTag);
180  void IncrByFloat(const string &key, double increment,
181  const DoubleCallback &callback,
182  const SerializationTag &tag = kDefaultSerializationTag);
183  void Decr(const string &key, const IntegerCallback &callback,
184  const SerializationTag &tag = kDefaultSerializationTag);
185  void DecrBy(const string &key, int64_t decrement,
186  const IntegerCallback &callback,
187  const SerializationTag &tag = kDefaultSerializationTag);
188  void StrLen(const string &key, const IntegerCallback &callback,
189  const SerializationTag &tag = kDefaultSerializationTag);
190  void Get(const string &key, const StringCallback &callback,
191  const SerializationTag &tag = kDefaultSerializationTag);
192  void MGet(const StringList &keys, const StringListCallback &callback,
193  const SerializationTag &tag = kDefaultSerializationTag);
194  void GetRange(const string &key, int64_t start, int64_t end,
195  const StringCallback &callback,
196  const SerializationTag &tag = kDefaultSerializationTag);
197  void GetSet(const string &key, const string &value,
198  const StringCallback &callback,
199  const SerializationTag &tag = kDefaultSerializationTag);
200  void Set(const string &key, const string &value,
201  const StringCallback &callback,
202  const SerializationTag &tag = kDefaultSerializationTag);
203  void Set(const string &key, const string &value,
204  CommandOption ex_or_px, uint64_t time,
205  CommandOption nx_or_xx, const StringCallback &callback,
206  const SerializationTag &tag = kDefaultSerializationTag);
207  void SetEx(const string &key, uint64_t seconds, const string &value,
208  const StringCallback &callback,
209  const SerializationTag &tag = kDefaultSerializationTag);
210  void PSetEx(const string &key, uint64_t milliseconds,
211  const string &value, const StringCallback &callback,
212  const SerializationTag &tag = kDefaultSerializationTag);
213  void SetNx(const string &key, const string &value,
214  const IntegerCallback &callback,
215  const SerializationTag &tag = kDefaultSerializationTag);
216  void MSet(const StringPairList &key_values, const StringCallback &callback,
217  const SerializationTag &tag = kDefaultSerializationTag);
218  void MSetNx(const StringPairList &key_values,
219  const IntegerCallback &callback,
220  const SerializationTag &tag = kDefaultSerializationTag);
221  void BitCount(const string &key, const IntegerCallback &callback,
222  const SerializationTag &tag = kDefaultSerializationTag);
223  void BitCount(const string &key, int64_t start, int64_t end,
224  const IntegerCallback &callback,
225  const SerializationTag &tag = kDefaultSerializationTag);
226  void BitOp(CommandOption operation, const string &dest_key,
227  const StringList &keys, const IntegerCallback &callback,
228  const SerializationTag &tag = kDefaultSerializationTag);
229  void GetBit(const string &key, uint64_t offset,
230  const IntegerCallback &callback,
231  const SerializationTag &tag = kDefaultSerializationTag);
232  void SetBit(const string &key, uint64_t offset, bool value,
233  const IntegerCallback &callback,
234  const SerializationTag &tag = kDefaultSerializationTag);
235 
236  Result AppendSync(const string &key, const string &value, int64_t *out);
237  Result IncrSync(const string &key, int64_t *out);
238  Result IncrBySync(const string &key, int64_t increment, int64_t *out);
239  Result IncrByFloatSync(const string &key, double increment, double *out);
240  Result DecrSync(const string &key, int64_t *out);
241  Result DecrBySync(const string &key, int64_t decrement, int64_t *out);
242  Result StrLenSync(const string &key, int64_t *out);
243  Result GetSync(const string &key, string *out);
244  Result MGetSync(const StringList &keys, StringList *out);
245  Result GetRangeSync(const string &key, int64_t start, int64_t end,
246  string *out);
247  Result GetSetSync(const string &key, const string &value, string *out);
248  Result SetSync(const string &key, const string &value, string *out);
249  Result SetSync(const string &key, const string &value,
250  CommandOption ex_or_px, uint64_t time,
251  CommandOption nx_or_xx, string *out);
252  Result SetExSync(const string &key, uint64_t seconds, const string &value,
253  string *out);
254  Result PSetExSync(const string &key, uint64_t milliseconds,
255  const string &value, string *out);
256  Result SetNxSync(const string &key, const string &value, int64_t *out);
257  Result MSetSync(const StringPairList &key_values, string *out);
258  Result MSetNxSync(const StringPairList &key_values, int64_t *out);
259  Result BitCountSync(const string &key, int64_t *out);
260  Result BitCountSync(const string &key, int64_t start, int64_t end,
261  int64_t *out);
262  Result BitOpSync(CommandOption operation, const string &dest_key,
263  const StringList &keys, int64_t *out);
264  Result GetBitSync(const string &key, uint64_t offset, int64_t *out);
265  Result SetBitSync(const string &key, uint64_t offset, bool value,
266  int64_t *out);
267 
269  void HExists(const string &key, const string &field,
270  const IntegerCallback &callback,
271  const SerializationTag &tag = kDefaultSerializationTag);
272  void HKeys(const string &key, const StringListCallback &callback,
273  const SerializationTag &tag = kDefaultSerializationTag);
274  void HVals(const string &key, const StringListCallback &callback,
275  const SerializationTag &tag = kDefaultSerializationTag);
276  void HLen(const string &key, const IntegerCallback &callback,
277  const SerializationTag &tag = kDefaultSerializationTag);
278  void HIncrBy(const string &key, const string &field, int64_t increment,
279  const IntegerCallback &callback,
280  const SerializationTag &tag = kDefaultSerializationTag);
281  void HIncrByFloat(const string &key, const string &field,
282  double increment, const DoubleCallback &callback,
283  const SerializationTag &tag = kDefaultSerializationTag);
284  void HDel(const string &key, const string &field,
285  const IntegerCallback &callback,
286  const SerializationTag &tag = kDefaultSerializationTag);
287  void HDel(const string &key, const StringList &fields,
288  const IntegerCallback &callback,
289  const SerializationTag &tag = kDefaultSerializationTag);
290  void HGet(const string &key, const string &field,
291  const StringCallback &callback,
292  const SerializationTag &tag = kDefaultSerializationTag);
293  void HGetAll(const string &key, const StringPairListCallback &callback,
294  const SerializationTag &tag = kDefaultSerializationTag);
295  void HMGet(const string &key, const StringList &fields,
296  const StringListCallback &callback,
297  const SerializationTag &tag = kDefaultSerializationTag);
298  void HSet(const string &key, const string &field, const string &value,
299  const IntegerCallback &callback,
300  const SerializationTag &tag = kDefaultSerializationTag);
301  void HSetNx(const string &key, const string &field, const string &value,
302  const IntegerCallback &callback,
303  const SerializationTag &tag = kDefaultSerializationTag);
304  void HMSet(const string &key, const StringPairList &field_values,
305  const StringCallback &callback,
306  const SerializationTag &tag = kDefaultSerializationTag);
307 
308  Result HExistsSync(const string &key, const string &field, int64_t *out);
309  Result HKeysSync(const string &key, StringList *out);
310  Result HValsSync(const string &key, StringList *out);
311  Result HLenSync(const string &key, int64_t *out);
312  Result HIncrBySync(const string &key, const string &field,
313  int64_t increment, int64_t *out);
314  Result HIncrByFloatSync(const string &key, const string &field,
315  double increment, double *out);
316  Result HDelSync(const string &key, const string &field, int64_t *out);
317  Result HDelSync(const string &key, const StringList &fields, int64_t *out);
318  Result HGetSync(const string &key, const string &field, string *out);
319  Result HGetAllSync(const string &key, StringPairList *out);
320  Result HMGetSync(const string &key, const StringList &fields,
321  StringList *out);
322  Result HSetSync(const string &key, const string &field, const string &value,
323  int64_t *out);
324  Result HSetNxSync(const string &key, const string &field, const string &value,
325  int64_t *out);
326  Result HMSetSync(const string &key, const StringPairList &field_values,
327  string *out);
328 
330  void LLen(const string &key, const IntegerCallback &callback,
331  const SerializationTag &tag = kDefaultSerializationTag);
332  void LIndex(const string &key, int64_t index, const StringCallback &callback,
333  const SerializationTag &tag = kDefaultSerializationTag);
334  void LRange(const string &key, int64_t start, int64_t stop,
335  const StringListCallback &callback,
336  const SerializationTag &tag = kDefaultSerializationTag);
337  void LRem(const string &key, int64_t count, const string &value,
338  const IntegerCallback &callback,
339  const SerializationTag &tag = kDefaultSerializationTag);
340  void LTrim(const string &key, int64_t start, int64_t stop,
341  const StringCallback &callback,
342  const SerializationTag &tag = kDefaultSerializationTag);
343  void LPush(const string &key, const string &value,
344  const IntegerCallback &callback,
345  const SerializationTag &tag = kDefaultSerializationTag);
346  void LPush(const string &key, const StringList &values,
347  const IntegerCallback &callback,
348  const SerializationTag &tag = kDefaultSerializationTag);
349  void RPush(const string &key, const string &value,
350  const IntegerCallback &callback,
351  const SerializationTag &tag = kDefaultSerializationTag);
352  void RPush(const string &key, const StringList &values,
353  const IntegerCallback &callback,
354  const SerializationTag &tag = kDefaultSerializationTag);
355  void LPop(const string &key, const StringCallback &callback,
356  const SerializationTag &tag = kDefaultSerializationTag);
357  void RPop(const string &key, const StringCallback &callback,
358  const SerializationTag &tag = kDefaultSerializationTag);
359  void LInsert(const string &key, CommandOption before_or_after,
360  const string &pivot, const string &value,
361  const IntegerCallback &callback,
362  const SerializationTag &tag = kDefaultSerializationTag);
363  void LSet(const string &key, int64_t index, const string &value,
364  const StringCallback &callback,
365  const SerializationTag &tag = kDefaultSerializationTag);
366 
367  Result LLenSync(const string &key, int64_t *out);
368  Result LIndexSync(const string &key, int64_t index, string *out);
369  Result LRangeSync(const string &key, int64_t start, int64_t stop,
370  StringList *out);
371  Result LRemSync(const string &key, int64_t count, const string &value,
372  int64_t *out);
373  Result LTrimSync(const string &key, int64_t start, int64_t stop,
374  string *out);
375  Result LPushSync(const string &key, const string &value, int64_t *out);
376  Result LPushSync(const string &key, const StringList &values,
377  int64_t *out);
378  Result RPushSync(const string &key, const string &value, int64_t *out);
379  Result RPushSync(const string &key, const StringList &values, int64_t *out);
380  Result LPopSync(const string &key, string *out);
381  Result RPopSync(const string &key, string *out);
382  Result LInsertSync(const string &key, CommandOption before_or_after,
383  const string &pivot, const string &value, int64_t *out);
384  Result LSetSync(const string &key, int64_t index, const string &value,
385  string *out);
386 
388  void SCard(const string &key, const IntegerCallback &callback,
389  const SerializationTag &tag = kDefaultSerializationTag);
390  void SIsMember(const string &key, const string &member,
391  const IntegerCallback &callback,
392  const SerializationTag &tag = kDefaultSerializationTag);
393  void SMembers(const string &key, const StringListCallback &callback,
394  const SerializationTag &tag = kDefaultSerializationTag);
395  void SRandMember(const string &key, const StringCallback &callback,
396  const SerializationTag &tag = kDefaultSerializationTag);
397  void SRandMember(const string &key, int64_t count,
398  const StringListCallback &callback,
399  const SerializationTag &tag = kDefaultSerializationTag);
400  void SDiff(const StringList &keys, const StringListCallback &callback,
401  const SerializationTag &tag = kDefaultSerializationTag);
402  void SDiffStore(const string &destination, const StringList &keys,
403  const IntegerCallback &callback,
404  const SerializationTag &tag = kDefaultSerializationTag);
405  void SInter(const StringList &keys, const StringListCallback &callback,
406  const SerializationTag &tag = kDefaultSerializationTag);
407  void SInterStore(const string &destination, const StringList &keys,
408  const IntegerCallback &callback,
409  const SerializationTag &tag = kDefaultSerializationTag);
410  void SUnion(const StringList &keys, const StringListCallback &callback,
411  const SerializationTag &tag = kDefaultSerializationTag);
412  void SUnionStore(const string &destination, const StringList &keys,
413  const IntegerCallback &callback,
414  const SerializationTag &tag = kDefaultSerializationTag);
415  void SAdd(const string &key, const string &member,
416  const IntegerCallback &callback,
417  const SerializationTag &tag = kDefaultSerializationTag);
418  void SAdd(const string &key, const StringList &members,
419  const IntegerCallback &callback,
420  const SerializationTag &tag = kDefaultSerializationTag);
421  void SPop(const string &key, const StringCallback &callback,
422  const SerializationTag &tag = kDefaultSerializationTag);
423  void SRem(const string &key, const string &member,
424  const IntegerCallback &callback,
425  const SerializationTag &tag = kDefaultSerializationTag);
426  void SRem(const string &key, const StringList &members,
427  const IntegerCallback &callback,
428  const SerializationTag &tag = kDefaultSerializationTag);
429  void SMove(const string &source, const string &destination,
430  const string &member, const IntegerCallback &callback,
431  const SerializationTag &tag = kDefaultSerializationTag);
432 
433  Result SCardSync(const string &key, int64_t *out);
434  Result SIsMemberSync(const string &key, const string &member, int64_t *out);
435  Result SMembersSync(const string &key, StringList *out);
436  Result SRandMemberSync(const string &key, string *out);
437  Result SRandMemberSync(const string &key, int64_t count, StringList *out);
438  Result SDiffSync(const StringList &keys, StringList *out);
439  Result SDiffStoreSync(const string &destination, const StringList &keys,
440  int64_t *out);
441  Result SInterSync(const StringList &keys, StringList *out);
442  Result SInterStoreSync(const string &destination, const StringList &keys,
443  int64_t *out);
444  Result SUnionSync(const StringList &keys, StringList *out);
445  Result SUnionStoreSync(const string &destination, const StringList &keys,
446  int64_t *out);
447  Result SAddSync(const string &key, const string &member,
448  int64_t *out);
449  Result SAddSync(const string &key, const StringList &members,
450  int64_t *out);
451  Result SPopSync(const string &key, string *out);
452  Result SRemSync(const string &key, const string &member, int64_t *out);
453  Result SRemSync(const string &key, const StringList &members,
454  int64_t *out);
455  Result SMoveSync(const string &source, const string &destination,
456  const string &member, int64_t *out);
457 
459  void ZCard(const string &key, const IntegerCallback &callback,
460  const SerializationTag &tag = kDefaultSerializationTag);
461  void ZCount(const string &key, const string &min, const string &max,
462  const IntegerCallback &callback,
463  const SerializationTag &tag = kDefaultSerializationTag);
464  void ZScore(const string &key, const string &member,
465  const DoubleCallback &callback,
466  const SerializationTag &tag = kDefaultSerializationTag);
467  void ZRange(const string &key, int64_t start, int64_t stop,
468  bool with_scores, const StringDoublePairListCallback &callback,
469  const SerializationTag &tag = kDefaultSerializationTag);
470  void ZRangeByScore(const string &key, const string &min, const string &max,
471  bool with_scores,
472  const StringDoublePairListCallback &callback,
473  const SerializationTag &tag = kDefaultSerializationTag);
474  void ZRangeByScore(const string &key, const string &min, const string &max,
475  bool with_scores, uint64_t offset, uint64_t count,
476  const StringDoublePairListCallback &callback,
477  const SerializationTag &tag = kDefaultSerializationTag);
478  void ZRank(const string &key, const string &member,
479  const IntegerCallback &callback,
480  const SerializationTag &tag = kDefaultSerializationTag);
481  void ZRevRange(const string &key, int64_t start, int64_t stop,
482  bool with_scores,
483  const StringDoublePairListCallback &callback,
484  const SerializationTag &tag = kDefaultSerializationTag);
485  void ZRevRangeByScore(const string &key, const string &max, const string &min,
486  bool with_scores,
487  const StringDoublePairListCallback &callback,
488  const SerializationTag &tag = kDefaultSerializationTag);
489  void ZRevRangeByScore(const string &key, const string &max, const string &min,
490  bool with_scores, uint64_t offset, uint64_t count,
491  const StringDoublePairListCallback &callback,
492  const SerializationTag &tag = kDefaultSerializationTag);
493  void ZRevRank(const string &key, const string &member,
494  const IntegerCallback &callback,
495  const SerializationTag &tag = kDefaultSerializationTag);
496  void ZAdd(const string &key, double score, const string &member,
497  const IntegerCallback &callback,
498  const SerializationTag &tag = kDefaultSerializationTag);
499  void ZAdd(const string &key, const StringDoublePairList &score_members,
500  const IntegerCallback &callback,
501  const SerializationTag &tag = kDefaultSerializationTag);
502  void ZIncrBy(const string &key, double increment, const string &member,
503  const DoubleCallback &callback,
504  const SerializationTag &tag = kDefaultSerializationTag);
505  void ZRem(const string &key, const string &member,
506  const IntegerCallback &callback,
507  const SerializationTag &tag = kDefaultSerializationTag);
508  void ZRem(const string &key, const StringList &members,
509  const IntegerCallback &callback,
510  const SerializationTag &tag = kDefaultSerializationTag);
511  void ZRemRangeByRank(const string &key, int64_t start, int64_t stop,
512  const IntegerCallback &callback,
513  const SerializationTag &tag = kDefaultSerializationTag);
514  void ZRemRangeByScore(const string &key, const string &min, const string &max,
515  const IntegerCallback &callback,
516  const SerializationTag &tag = kDefaultSerializationTag);
517 
518  Result ZCardSync(const string &key, int64_t *out);
519  Result ZCountSync(const string &key, const string &min, const string &max,
520  int64_t *out);
521  Result ZScoreSync(const string &key, const string &member, double *out);
522  Result ZRangeSync(const string &key, int64_t start, int64_t stop,
523  bool with_scores, StringDoublePairList *out);
524  Result ZRangeByScoreSync(const string &key, const string &min,
525  const string &max, bool with_scores,
526  StringDoublePairList *out);
527  Result ZRangeByScoreSync(const string &key, const string &min,
528  const string &max, bool with_scores,
529  uint64_t offset, uint64_t count,
530  StringDoublePairList *out);
531  Result ZRankSync(const string &key, const string &member, int64_t *out);
532  Result ZRevRangeSync(const string &key, int64_t start, int64_t stop,
533  bool with_scores, StringDoublePairList *out);
534  Result ZRevRangeByScoreSync(const string &key, const string &max,
535  const string &min, bool with_scores,
536  StringDoublePairList *out);
537  Result ZRevRangeByScoreSync(const string &key, const string &max,
538  const string &min, bool with_scores,
539  uint64_t offset, uint64_t count,
540  StringDoublePairList *out);
541  Result ZRevRankSync(const string &key, const string &member, int64_t *out);
542  Result ZAddSync(const string &key, double score, const string &member,
543  int64_t *out);
544  Result ZAddSync(const string &key, const StringDoublePairList &score_members,
545  int64_t *out);
546  Result ZIncrBySync(const string &key, double increment, const string &member,
547  double *out);
548  Result ZRemSync(const string &key, const string &member, int64_t *out);
549  Result ZRemSync(const string &key, const StringList &members, int64_t *out);
550  Result ZRemRangeByRankSync(const string &key, int64_t start, int64_t stop,
551  int64_t *out);
552  Result ZRemRangeByScoreSync(const string &key, const string &min,
553  const string &max, int64_t *out);
554 
556  void Publish(const string &channel, const string &message,
557  const IntegerCallback &callback,
558  const SerializationTag &tag = kDefaultSerializationTag);
559  void Subscribe(const string &channel, const SubCallback &callback);
560  void Subscribe(const std::vector<string> &channels,
561  const SubCallback &callback);
562  void PSubscribe(const string &pattern, const PSubCallback &callback);
563  void PSubscribe(const std::vector<string> &patterns,
564  const PSubCallback &callback);
565  void Unsubscribe();
566  void Unsubscribe(const string &channel);
567  void Unsubscribe(const std::vector<string> &channels);
568  void PUnsubscribe();
569  void PUnsubscribe(const string &pattern);
570  void PUnsubscribe(const std::vector<string> &patterns);
571 
572  Result PublishSync(const string &channel, const string &message,
573  int64_t *out);
574 
575  void ExecuteCommand(const string &command_name,
576  const std::vector<string> *arguments,
577  const Callback &callback,
578  const SerializationTag &tag = kDefaultSerializationTag);
579  Ptr<Reply> ExecuteCommandSync(const string &command_name,
580  const std::vector<string> *arguments,
581  Result *result = NULL);
582 
583  private:
584  class Impl;
585 
586  RedisClient(const string &server_ip, int server_port,
587  const string &auth_pass, size_t connection_count,
588  bool invoke_as_event, size_t database);
589 
590  RedisClient(const string &master_name,
591  const std::vector<string> &sentinel_addresses,
592  const string &auth_pass, size_t connection_count,
593  bool invoke_as_event, size_t database);
594 
595  Ptr<Impl> impl_;
596 };
597 
598 
599 FUNAPI_DLL_VISIBILITY
600 std::ostream &operator<<(std::ostream &stream,
601  const RedisClient::Result &result);
602 
603 } // namespace fun
604 
605 #endif // INCLUDE_FUNAPI_DATABASE_REDIS_CLIENT_H_
Definition: redis_client.h:22
boost::function< void(const string &, const string &, const string &)> SentinelMasterSwitchedCallback
for Redis Sentinel
Definition: redis_client.h:101
Definition: redis_client.h:38
Definition: json.h:18
Definition: redis_client.h:24
boost::uuids::uuid Uuid
UUID type used throughout Funapi.
Definition: types.h:56
Definition: json.h:27
#define DECLARE_CLASS_PTR(CLS)
Utility macro to forward-declare smart pointer types for a given class.
Definition: types.h:89