|
33 | 33 | #include <SAPI.h> |
34 | 34 |
|
35 | 35 | zend_class_entry *redis_cluster_ce; |
36 | | -int le_cluster_slot_cache; |
37 | 36 |
|
38 | 37 | /* Exception handler */ |
39 | 38 | zend_class_entry *redis_cluster_exception_ce; |
@@ -343,85 +342,6 @@ void free_cluster_context(zend_object *object) { |
343 | 342 | zend_object_std_dtor(&cluster->std); |
344 | 343 | } |
345 | 344 |
|
346 | | -/* Turn a seed array into a zend_string we can use to look up a slot cache */ |
347 | | -static zend_string *cluster_hash_seeds(HashTable *ht) { |
348 | | - smart_str hash = {0}; |
349 | | - zend_string *zstr; |
350 | | - zval *z_seed; |
351 | | - |
352 | | - ZEND_HASH_FOREACH_VAL(ht, z_seed) { |
353 | | - zstr = zval_get_string(z_seed); |
354 | | - smart_str_appendc(&hash, '['); |
355 | | - smart_str_appendl(&hash, ZSTR_VAL(zstr), ZSTR_LEN(zstr)); |
356 | | - smart_str_appendc(&hash, ']'); |
357 | | - zend_string_release(zstr); |
358 | | - } ZEND_HASH_FOREACH_END(); |
359 | | - |
360 | | - /* Not strictly needed but null terminate anyway */ |
361 | | - smart_str_0(&hash); |
362 | | - |
363 | | - /* smart_str is a zend_string internally */ |
364 | | - return hash.s; |
365 | | -} |
366 | | - |
367 | | -#define SLOT_CACHING_ENABLED() (INI_INT("redis.clusters.cache_slots") == 1) |
368 | | -static redisCachedCluster *cluster_cache_load(HashTable *ht_seeds) { |
369 | | - zend_resource *le; |
370 | | - zend_string *h; |
371 | | - |
372 | | - /* Short circuit if we're not caching slots or if our seeds don't have any |
373 | | - * elements, since it doesn't make sense to cache an empty string */ |
374 | | - if (!SLOT_CACHING_ENABLED() || zend_hash_num_elements(ht_seeds) == 0) |
375 | | - return NULL; |
376 | | - |
377 | | - /* Look for cached slot information */ |
378 | | - h = cluster_hash_seeds(ht_seeds); |
379 | | - le = zend_hash_str_find_ptr(&EG(persistent_list), ZSTR_VAL(h), ZSTR_LEN(h)); |
380 | | - zend_string_release(h); |
381 | | - |
382 | | - if (le != NULL) { |
383 | | - /* Sanity check on our list type */ |
384 | | - if (le->type != le_cluster_slot_cache) { |
385 | | - php_error_docref(0, E_WARNING, "Invalid slot cache resource"); |
386 | | - return NULL; |
387 | | - } |
388 | | - |
389 | | - /* Success, return the cached entry */ |
390 | | - return le->ptr; |
391 | | - } |
392 | | - |
393 | | - /* Not found */ |
394 | | - return NULL; |
395 | | -} |
396 | | - |
397 | | -/* Cache a cluster's slot information in persistent_list if it's enabled */ |
398 | | -static int cluster_cache_store(HashTable *ht_seeds, HashTable *nodes) { |
399 | | - redisCachedCluster *cc; |
400 | | - zend_string *hash; |
401 | | - |
402 | | - /* Short circuit if caching is disabled or there aren't any seeds */ |
403 | | - if (!SLOT_CACHING_ENABLED() || zend_hash_num_elements(ht_seeds) == 0) |
404 | | - return !SLOT_CACHING_ENABLED() ? SUCCESS : FAILURE; |
405 | | - |
406 | | - /* Construct our cache */ |
407 | | - hash = cluster_hash_seeds(ht_seeds); |
408 | | - cc = cluster_cache_create(hash, nodes); |
409 | | - zend_string_release(hash); |
410 | | - |
411 | | - /* Set up our resource */ |
412 | | -#if PHP_VERSION_ID < 70300 |
413 | | - zend_resource le; |
414 | | - le.type = le_cluster_slot_cache; |
415 | | - le.ptr = cc; |
416 | | - |
417 | | - zend_hash_update_mem(&EG(persistent_list), cc->hash, (void*)&le, sizeof(zend_resource)); |
418 | | -#else |
419 | | - zend_register_persistent_resource_ex(cc->hash, cc, le_cluster_slot_cache); |
420 | | -#endif |
421 | | - |
422 | | - return SUCCESS; |
423 | | -} |
424 | | - |
425 | 345 | /* Validate redis cluster construction arguments */ |
426 | 346 | static int |
427 | 347 | cluster_validate_args(double timeout, double read_timeout, HashTable *seeds) { |
|
0 commit comments