Redis4Qt  1.0.0
Redis API for Qt framework
redis4qt.h
1 #ifndef REDIS4QT_H
2 #define REDIS4QT_H
3 
4 #include "redis4qt_global.h"
5 #include "redis_types.h"
6 #include <QObject>
7 #include <QMutex>
8 #include <QSettings>
9 
10 using namespace Redis4Qt_Types;
11 
12 class RedisCore;
13 class QTimer;
14 
15 struct ThreadRedis
16 {
17  QMutex* lock;
18  QThread* thread;
19  RedisCore* core;
20 };
21 
22 class REDIS4QTAPI Redis4Qt : public QObject
23 {
24  Q_OBJECT
25 public:
26  Redis4Qt();
27  ~Redis4Qt();
32  void setRedisCof(QString strCfg);
33 
40  int key_del(QString key, bool *error = NULL);
41 
48  QString key_dump(QString key, bool *error = NULL);
49 
56  bool key_exists(QString key, bool *error = NULL);
57 
65  bool key_expire(QString key,int seconds, bool *error = NULL);
66 
74  bool key_expireat(QString key, qint64 timestamp, bool *error = NULL);
75 
82  QStringList keys(QString pattern, bool *error = NULL);
83 
90  int key_pttl(QString key, bool *error = NULL);
91 
98  int key_ttl(QString key, bool *error = NULL);
99 
107  bool key_rename(QString key, QString newkey, bool *error = NULL);
108 
115  QString key_type(QString key, bool *error = NULL);
116 
117 
125  bool string_set(QString key, QString value, bool *error = NULL);
126 
133  QString string_get(QString key, bool *error = NULL);
134 
143  QString string_getrange(QString key, int start, int stop, bool *error = NULL);
144 
151  QStringList string_mget(QStringList keys, bool *error = NULL);
152 
159  bool string_mset(QMap<QString, QVariant> map, bool *error = NULL);
160 
167  int string_incr(QString key, bool *error = NULL);
168 
176  int string_incrby(QString key,int interval, bool *error = NULL);
177 
184  int string_decr(QString key, bool *error = NULL);
185 
193  int string_decrby(QString key,int interval, bool *error = NULL);
194 
202  int string_append(QString key, QString value, bool *error = NULL);
203 
204 
212  QStringList list_blpop(QString key, int timeout, bool *error = NULL);
213 
221  QStringList list_brpop(QString key, int timeout, bool *error = NULL);
222 
231  QStringList list_brpoplpush(QString source, QString destination, int timeout, bool *error = NULL);
232 
240  QString list_index(QString key, int index, bool *error = NULL);
241 
252  int list_insert(QString key, QString position, QString pivot, QString value, bool *error = NULL);
253 
260  int list_len(QString key, bool *error = NULL);
261 
268  QString list_lpop(QString key, bool *error = NULL);
269 
277  int list_lpush(QString key, QString value, bool *error = NULL);
278 
286  int list_lpush(QString key, QStringList values, bool *error = NULL);
287 
295  int list_lpushx(QString key, QStringList values, bool *error = NULL);
296 
306  QStringList list_range(QString key, int start, int end, bool *error = NULL);
307 
320  int list_rem(QString key, int count, QString value, bool *error = NULL);
321 
331  int list_set(QString key, int index, QString value, bool *error = NULL);
332 
343  bool list_trim(QString key, int start, int stop, bool *error = NULL);
344 
351  QString list_rpop(QString key, bool *error = NULL);
352 
360  QString list_rpoplpush(QString source, QString destination, bool *error = NULL);
361 
369  int list_rpush(QString key, QString value, bool *error = NULL);
370 
378  int list_rpush(QString key, QStringList values, bool *error = NULL);
379 
387  int list_rpushx(QString key, QStringList values, bool *error = NULL);
388 
389 
399  int set_add(QString key, QString member, bool *error = NULL);
400 
410  int set_add(QString key, QStringList members, bool *error = NULL);
411 
418  int set_card(QString key, bool *error = NULL);
419 
426  QStringList set_diff(QStringList keys, bool *error = NULL);
427 
435  int set_diffstore(QString destination, QStringList keys, bool *error = NULL);
436 
443  QStringList set_inter(QStringList keys, bool *error = NULL);
444 
452  int set_interstore(QString destination, QStringList keys, bool *error = NULL);
453 
461  bool set_ismember(QString key, QString member, bool *error = NULL);
462 
469  QStringList set_members(QString key, bool *error = NULL);
470 
483  bool set_move(QString source, QString destination, QString member, bool *error = NULL);
484 
491  QString set_pop(QString key, bool *error = NULL);
492 
500  QStringList set_randmember(QString key, bool *error = NULL);
501 
512  QStringList set_randmember(QString key, int count, bool *error = NULL);
513 
521  int set_rem(QString key, QString member, bool *error = NULL);
522 
530  int set_rem(QString key, QStringList members, bool *error = NULL);
531 
538  QStringList set_union(QStringList keys, bool *error = NULL);
539 
547  int set_unionstore(QString destination, QStringList keys, bool *error = NULL);
548 
549 
557  int hash_del(QString key, QString field, bool *error = NULL);
558 
566  int hash_del(QString key, QStringList fields, bool *error = NULL);
567 
575  bool hash_exists(QString key, QString field, bool *error = NULL);
576 
584  QString hash_get(QString key, QString field, bool *error = NULL);
585 
592  QVariantMap hash_getall(QString key, bool *error = NULL);
593 
607  int hash_incrby(QString key, QString field, int increment, bool *error = NULL);
608 
617  float hash_incrbyfloat(QString key, QString field, float increment, bool *error = NULL);
618 
625  QStringList hash_keys(QString key, bool *error = NULL);
626 
633  int hash_len(QString key, bool *error = NULL);
634 
642  QStringList hash_mget(QString key, QStringList fields, bool *error = NULL);
643 
651  bool hash_mset(QString key, QMap<QString,QVariant> map, bool *error = NULL);
652 
661  bool hash_set(QString key, QString field, QString value, bool *error = NULL);
662 
674  bool hash_setnx(QString key, QString field, QString value, bool *error = NULL);
675 
682  QStringList hash_values(QString key, bool *error = NULL);
683 
690  void publish(QString channel, QString message, bool *error = NULL);
691 
697  void subscribe(QString channel, bool *error = NULL);
698 
704  void unsubscribe(QString channel, bool *error = NULL);
705 
712  void psubscribe(QString channel, bool *error = NULL);
713 
719  void punsubscribe(QString channel, bool *error = NULL);
720 
725  int getLastError();
726 
727 private:
728  RedisCore *getRedisInstance();
729  bool validKey(QString &key, QString funcName, bool *error);
730  bool validKeys(QStringList &key, QString funcName, bool *error);
731  void setLastError(int error);
732  QVariant dealwithCmd(FuncType type, QVariantList &data, bool *error);
733  QVariant excuteCmd(FuncType type, RedisCore* redis, QVariantList &data);
734 
735 private:
736  QString m_redisHost;
737  qint16 m_redisPort;
738  int m_redisCmdTimeout;
739  QMap<void *, ThreadRedis> m_redis;
740  QSettings *m_Settings;
741  QMutex m_Lock;
742 };
743 
744 #endif // REDIS4QT_H
Definition: redis4qt.h:22
Definition: redis_types.h:13
Definition: lht_redis.h:17
Definition: redis_core.h:13