redissync.hpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef ECL_REDIS_SYNC_INCL
  14. #define ECL_REDIS_SYNC_INCL
  15. #include "redisplugin.hpp"
  16. namespace RedisPlugin
  17. {
  18. class SyncConnection : public Connection
  19. {
  20. public :
  21. SyncConnection(ICodeContext * ctx, const char * options, unsigned __int64 database, const char * pswd, unsigned __int64 _timeout);
  22. SyncConnection(ICodeContext * ctx, RedisServer * _server, unsigned __int64 database, const char * pswd);
  23. ~SyncConnection()
  24. {
  25. if (context)
  26. redisFree(context);
  27. }
  28. static SyncConnection * createConnection(ICodeContext * ctx, const char * options, unsigned __int64 database, const char * pswd, unsigned __int64 _timeout);
  29. //set
  30. template <class type> void set(ICodeContext * ctx, const char * key, type value, unsigned expire);
  31. template <class type> void set(ICodeContext * ctx, const char * key, size32_t valueLength, const type * value, unsigned expire);
  32. //get
  33. template <class type> void get(ICodeContext * ctx, const char * key, type & value);
  34. template <class type> void get(ICodeContext * ctx, const char * key, size_t & valueLength, type * & value);
  35. void getVoidPtrLenPair(ICodeContext * ctx, const char * key, size_t & valueLength, void * & value);
  36. void persist(ICodeContext * ctx, const char * key);
  37. void expire(ICodeContext * ctx, const char * key, unsigned _expire);
  38. void del(ICodeContext * ctx, const char * key);
  39. void clear(ICodeContext * ctx);
  40. unsigned __int64 dbSize(ICodeContext * ctx);
  41. bool exists(ICodeContext * ctx, const char * key);
  42. protected :
  43. void connect(ICodeContext * ctx, unsigned __int64 _database, const char * pswd);
  44. void selectDB(ICodeContext * ctx, unsigned __int64 _database);
  45. void authenticate(ICodeContext * ctx, const char * pswd);
  46. void resetContextErr();
  47. virtual void updateTimeout(unsigned __int64 _timeout);
  48. virtual void assertOnError(const redisReply * reply, const char * _msg);
  49. virtual void assertConnection();
  50. virtual void logServerStats(ICodeContext * ctx);
  51. protected :
  52. redisContext * context;
  53. };
  54. }//close namespace
  55. extern "C++"
  56. {
  57. namespace RedisPlugin {
  58. //--------------------------SET----------------------------------------
  59. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetBool (ICodeContext * _ctx, const char * key, bool value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  60. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetInt (ICodeContext * _ctx, const char * key, signed __int64 value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  61. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetUInt (ICodeContext * _ctx, const char * key, unsigned __int64 value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  62. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetReal (ICodeContext * _ctx, const char * key, double value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  63. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetUtf8 (ICodeContext * _ctx, const char * key, size32_t valueLength, const char * value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  64. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetStr (ICodeContext * _ctx, const char * key, size32_t valueLength, const char * value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  65. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetUChar(ICodeContext * _ctx, const char * key, size32_t valueLength, const UChar * value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  66. ECL_REDIS_API void ECL_REDIS_CALL SyncRSetData (ICodeContext * _ctx, const char * key, size32_t valueLength, const void * value, const char * options, unsigned __int64 database, unsigned expire, const char * pswd, unsigned timeout);
  67. //--------------------------GET----------------------------------------
  68. ECL_REDIS_API bool ECL_REDIS_CALL SyncRGetBool (ICodeContext * _ctx, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  69. ECL_REDIS_API signed __int64 ECL_REDIS_CALL SyncRGetInt8 (ICodeContext * _ctx, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  70. ECL_REDIS_API unsigned __int64 ECL_REDIS_CALL SyncRGetUint8 (ICodeContext * _ctx, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  71. ECL_REDIS_API double ECL_REDIS_CALL SyncRGetDouble(ICodeContext * _ctx, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  72. ECL_REDIS_API void ECL_REDIS_CALL SyncRGetUtf8 (ICodeContext * _ctx, size32_t & returnLength, char * & returnValue, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  73. ECL_REDIS_API void ECL_REDIS_CALL SyncRGetStr (ICodeContext * _ctx, size32_t & returnLength, char * & returnValue, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  74. ECL_REDIS_API void ECL_REDIS_CALL SyncRGetUChar (ICodeContext * _ctx, size32_t & returnLength, UChar * & returnValue, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  75. ECL_REDIS_API void ECL_REDIS_CALL SyncRGetData (ICodeContext * _ctx,size32_t & returnLength, void * & returnValue, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  76. //--------------------------------AUXILLARIES---------------------------
  77. ECL_REDIS_API bool ECL_REDIS_CALL RExist (ICodeContext * _ctx, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  78. ECL_REDIS_API void ECL_REDIS_CALL RClear (ICodeContext * _ctx, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  79. ECL_REDIS_API void ECL_REDIS_CALL RDel (ICodeContext * _ctx, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  80. ECL_REDIS_API void ECL_REDIS_CALL RPersist(ICodeContext * _ctx, const char * key, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  81. ECL_REDIS_API void ECL_REDIS_CALL RExpire (ICodeContext * _ctx, const char * key, const char * options, unsigned expire, unsigned __int64 database, const char * pswd, unsigned timeout);
  82. ECL_REDIS_API unsigned __int64 ECL_REDIS_CALL RDBSize (ICodeContext * _ctx, const char * options, unsigned __int64 database, const char * pswd, unsigned timeout);
  83. }
  84. }
  85. #endif