Apache Portable Runtime Utility Library
|
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more 00002 * contributor license agreements. See the NOTICE file distributed with 00003 * this work for additional information regarding copyright ownership. 00004 * The ASF licenses this file to You under the Apache License, Version 2.0 00005 * (the "License"); you may not use this file except in compliance with 00006 * the License. You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00024 #ifndef APR_REDIS_H 00025 #define APR_REDIS_H 00026 00027 #include "apr.h" 00028 #include "apr_pools.h" 00029 #include "apr_time.h" 00030 #include "apr_strings.h" 00031 #include "apr_network_io.h" 00032 #include "apr_ring.h" 00033 #include "apr_buckets.h" 00034 #include "apr_reslist.h" 00035 #include "apr_hash.h" 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif /* __cplusplus */ 00040 00041 #ifndef RC_DEFAULT_SERVER_PORT 00042 #define RC_DEFAULT_SERVER_PORT 6379 00043 #endif 00044 00045 #ifndef RC_DEFAULT_SERVER_MIN 00046 #define RC_DEFAULT_SERVER_MIN 0 00047 #endif 00048 00049 #ifndef RC_DEFAULT_SERVER_SMAX 00050 #define RC_DEFAULT_SERVER_SMAX 1 00051 #endif 00052 00053 #ifndef RC_DEFAULT_SERVER_TTL 00054 #define RC_DEFAULT_SERVER_TTL 600 00055 #endif 00056 00064 typedef enum 00065 { 00066 APR_RC_SERVER_LIVE, 00067 APR_RC_SERVER_DEAD 00068 } apr_redis_server_status_t; 00069 00071 typedef struct apr_redis_conn_t apr_redis_conn_t; 00072 00074 typedef struct apr_redis_server_t apr_redis_server_t; 00075 struct apr_redis_server_t 00076 { 00077 const char *host; 00078 apr_port_t port; 00079 apr_redis_server_status_t status; 00080 #if APR_HAS_THREADS || defined(DOXYGEN) 00081 apr_reslist_t *conns; 00082 #else 00083 apr_redis_conn_t *conn; 00084 #endif 00085 apr_pool_t *p; 00086 #if APR_HAS_THREADS 00087 apr_thread_mutex_t *lock; 00088 #endif 00089 apr_time_t btime; 00090 apr_uint32_t rwto; 00091 struct 00092 { 00093 int major; 00094 int minor; 00095 int patch; 00096 char *number; 00097 } version; 00098 }; 00099 00100 typedef struct apr_redis_t apr_redis_t; 00101 00102 /* Custom hash callback function prototype, user for server selection. 00103 * @param baton user selected baton 00104 * @param data data to hash 00105 * @param data_len length of data 00106 */ 00107 typedef apr_uint32_t (*apr_redis_hash_func)(void *baton, 00108 const char *data, 00109 const apr_size_t data_len); 00110 /* Custom Server Select callback function prototype. 00111 * @param baton user selected baton 00112 * @param rc redis instance, use rc->live_servers to select a node 00113 * @param hash hash of the selected key. 00114 */ 00115 typedef apr_redis_server_t* (*apr_redis_server_func)(void *baton, 00116 apr_redis_t *rc, 00117 const apr_uint32_t hash); 00118 00120 struct apr_redis_t 00121 { 00122 apr_uint32_t flags; 00123 apr_uint16_t nalloc; 00124 apr_uint16_t ntotal; 00125 apr_redis_server_t **live_servers; 00126 apr_pool_t *p; 00127 void *hash_baton; 00128 apr_redis_hash_func hash_func; 00129 void *server_baton; 00130 apr_redis_server_func server_func; 00131 }; 00132 00141 APU_DECLARE(apr_uint32_t) apr_redis_hash(apr_redis_t *rc, 00142 const char *data, 00143 const apr_size_t data_len); 00144 00148 APU_DECLARE(apr_uint32_t) apr_redis_hash_crc32(void *baton, 00149 const char *data, 00150 const apr_size_t data_len); 00151 00155 APU_DECLARE(apr_uint32_t) apr_redis_hash_default(void *baton, 00156 const char *data, 00157 const apr_size_t data_len); 00158 00166 APU_DECLARE(apr_redis_server_t *) apr_redis_find_server_hash(apr_redis_t *rc, 00167 const apr_uint32_t hash); 00168 00172 APU_DECLARE(apr_redis_server_t *) apr_redis_find_server_hash_default(void *baton, 00173 apr_redis_t *rc, 00174 const apr_uint32_t hash); 00175 00184 APU_DECLARE(apr_status_t) apr_redis_add_server(apr_redis_t *rc, 00185 apr_redis_server_t *server); 00186 00187 00195 APU_DECLARE(apr_redis_server_t *) apr_redis_find_server(apr_redis_t *rc, 00196 const char *host, 00197 apr_port_t port); 00198 00204 APU_DECLARE(apr_status_t) apr_redis_enable_server(apr_redis_t *rc, 00205 apr_redis_server_t *rs); 00206 00207 00213 APU_DECLARE(apr_status_t) apr_redis_disable_server(apr_redis_t *rc, 00214 apr_redis_server_t *rs); 00215 00230 APU_DECLARE(apr_status_t) apr_redis_server_create(apr_pool_t *p, 00231 const char *host, 00232 apr_port_t port, 00233 apr_uint32_t min, 00234 apr_uint32_t smax, 00235 apr_uint32_t max, 00236 apr_uint32_t ttl, 00237 apr_uint32_t rwto, 00238 apr_redis_server_t **ns); 00246 APU_DECLARE(apr_status_t) apr_redis_create(apr_pool_t *p, 00247 apr_uint16_t max_servers, 00248 apr_uint32_t flags, 00249 apr_redis_t **rc); 00250 00261 APU_DECLARE(apr_status_t) apr_redis_getp(apr_redis_t *rc, 00262 apr_pool_t *p, 00263 const char* key, 00264 char **baton, 00265 apr_size_t *len, 00266 apr_uint16_t *flags); 00267 00276 APU_DECLARE(apr_status_t) apr_redis_set(apr_redis_t *rc, 00277 const char *key, 00278 char *baton, 00279 const apr_size_t data_size, 00280 apr_uint16_t flags); 00281 00291 APU_DECLARE(apr_status_t) apr_redis_setex(apr_redis_t *rc, 00292 const char *key, 00293 char *baton, 00294 const apr_size_t data_size, 00295 apr_uint32_t timeout, 00296 apr_uint16_t flags); 00297 00304 APU_DECLARE(apr_status_t) apr_redis_delete(apr_redis_t *rc, 00305 const char *key, 00306 apr_uint32_t timeout); 00307 00314 APU_DECLARE(apr_status_t) apr_redis_version(apr_redis_server_t *rs, 00315 apr_pool_t *p, 00316 char **baton); 00317 00324 APU_DECLARE(apr_status_t) apr_redis_info(apr_redis_server_t *rs, 00325 apr_pool_t *p, 00326 char **baton); 00327 00335 APU_DECLARE(apr_status_t) apr_redis_incr(apr_redis_t *rc, 00336 const char *key, 00337 apr_int32_t inc, 00338 apr_uint32_t *new_value); 00346 APU_DECLARE(apr_status_t) apr_redis_decr(apr_redis_t *rc, 00347 const char *key, 00348 apr_int32_t inc, 00349 apr_uint32_t *new_value); 00350 00351 00356 APU_DECLARE(apr_status_t) apr_redis_ping(apr_redis_server_t *rs); 00357 00368 APU_DECLARE(apr_status_t) apr_redis_multgetp(apr_redis_t *rc, 00369 apr_pool_t *temp_pool, 00370 apr_pool_t *data_pool, 00371 apr_hash_t *values); 00372 00373 typedef enum 00374 { 00375 APR_RS_SERVER_MASTER, 00376 APR_RS_SERVER_SLAVE, 00377 APR_RS_SERVER_UNKNOWN 00378 } apr_redis_server_role_t; 00379 00380 typedef struct 00381 { 00382 /* # Server */ 00384 apr_uint32_t major; 00386 apr_uint32_t minor; 00388 apr_uint32_t patch; 00390 apr_uint32_t process_id; 00392 apr_uint32_t uptime_in_seconds; 00394 apr_uint32_t arch_bits; 00395 00396 /* # Clients */ 00398 apr_uint32_t connected_clients; 00400 apr_uint32_t blocked_clients; 00401 00402 /* # Memory */ 00404 apr_uint64_t maxmemory; 00406 apr_uint64_t used_memory; 00408 apr_uint64_t total_system_memory; 00409 00410 /* # Stats */ 00412 apr_uint64_t total_connections_received; 00414 apr_uint64_t total_commands_processed; 00416 apr_uint64_t rejected_connections; 00418 apr_uint64_t total_net_input_bytes; 00420 apr_uint64_t total_net_output_bytes; 00422 apr_uint64_t keyspace_hits; 00424 apr_uint64_t keyspace_misses; 00425 00426 /* # Replication */ 00428 apr_redis_server_role_t role; 00430 apr_uint32_t connected_slaves; 00431 00432 /* # CPU */ 00434 apr_uint32_t used_cpu_sys; 00436 apr_uint32_t used_cpu_user; 00437 00438 /* # Cluster */ 00440 apr_uint32_t cluster_enabled; 00441 } apr_redis_stats_t; 00442 00449 APU_DECLARE(apr_status_t) apr_redis_stats(apr_redis_server_t *rs, 00450 apr_pool_t *p, 00451 apr_redis_stats_t **stats); 00452 00455 #ifdef __cplusplus 00456 } 00457 #endif 00458 00459 #endif /* APR_REDIS_H */