You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

redis_pool.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SRC_LIBSERVER_REDIS_POOL_H_
  17. #define SRC_LIBSERVER_REDIS_POOL_H_
  18. #include "config.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. struct rspamd_config;
  23. struct redisAsyncContext;
  24. struct ev_loop;
  25. /**
  26. * Creates new redis pool
  27. * @return
  28. */
  29. void *rspamd_redis_pool_init(void);
  30. /**
  31. * Configure redis pool and binds it to a specific event base
  32. * @param cfg
  33. * @param ev_base
  34. */
  35. void rspamd_redis_pool_config(void *pool,
  36. struct rspamd_config *cfg,
  37. struct ev_loop *ev_base);
  38. /**
  39. * Create or reuse the specific redis connection
  40. * @param pool
  41. * @param db
  42. * @param username
  43. * @param password
  44. * @param ip
  45. * @param port
  46. * @return
  47. */
  48. struct redisAsyncContext *rspamd_redis_pool_connect(
  49. void *pool,
  50. const char *db, const char *username, const char *password,
  51. const char *ip, int port);
  52. enum rspamd_redis_pool_release_type {
  53. RSPAMD_REDIS_RELEASE_DEFAULT = 0,
  54. RSPAMD_REDIS_RELEASE_FATAL = 1,
  55. RSPAMD_REDIS_RELEASE_ENFORCE
  56. };
  57. /**
  58. * Release a connection to the pool
  59. * @param pool
  60. * @param ctx
  61. */
  62. void rspamd_redis_pool_release_connection(void *pool,
  63. struct redisAsyncContext *ctx,
  64. enum rspamd_redis_pool_release_type how);
  65. /**
  66. * Stops redis pool and destroys it
  67. * @param pool
  68. */
  69. void rspamd_redis_pool_destroy(void *pool);
  70. /**
  71. * Missing in hiredis
  72. * @param type
  73. * @return
  74. */
  75. const char *rspamd_redis_type_to_string(int type);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif /* SRC_LIBSERVER_REDIS_POOL_H_ */