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.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_redis_pool;
  23. struct rspamd_config;
  24. struct redisAsyncContext;
  25. struct ev_loop;
  26. /**
  27. * Creates new redis pool
  28. * @return
  29. */
  30. struct rspamd_redis_pool *rspamd_redis_pool_init (void);
  31. /**
  32. * Configure redis pool and binds it to a specific event base
  33. * @param cfg
  34. * @param ev_base
  35. */
  36. void rspamd_redis_pool_config (struct rspamd_redis_pool *pool,
  37. struct rspamd_config *cfg,
  38. struct ev_loop *ev_base);
  39. /**
  40. * Create or reuse the specific redis connection
  41. * @param pool
  42. * @param db
  43. * @param password
  44. * @param ip
  45. * @param port
  46. * @return
  47. */
  48. struct redisAsyncContext *rspamd_redis_pool_connect (
  49. struct rspamd_redis_pool *pool,
  50. const gchar *db, const gchar *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 (struct rspamd_redis_pool *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 (struct rspamd_redis_pool *pool);
  70. /**
  71. * Missing in hiredis
  72. * @param type
  73. * @return
  74. */
  75. const gchar *rspamd_redis_type_to_string (int type);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif /* SRC_LIBSERVER_REDIS_POOL_H_ */