@@ -164,7 +164,8 @@ static memcached_return_t ascii_get_by_key(memcached_st *ptr,
164164 uint32_t master_server_key,
165165 bool is_group_key_set,
166166 const char *key,
167- const size_t key_length)
167+ const size_t key_length,
168+ time_t *expiration)
168169{
169170 memcached_return_t rc;
170171 memcached_server_write_instance_st instance;
@@ -180,16 +181,33 @@ static memcached_return_t ascii_get_by_key(memcached_st *ptr,
180181 }
181182 instance= memcached_server_instance_fetch (ptr, server_key);
182183
183- const char *command= (ptr->flags .support_cas ? " gets " : " get " );
184+ char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1 + 1 ];
185+ int expiration_buffer_length = 0 ;
186+ if (expiration) {
187+ expiration_buffer_length = snprintf (expiration_buffer, sizeof (expiration_buffer), " %lld " ,
188+ (long long ) *expiration);
189+ if (size_t (expiration_buffer_length) >= sizeof (expiration_buffer)
190+ or expiration_buffer_length < 0 )
191+ {
192+ return memcached_set_error (*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT,
193+ memcached_literal_param (" snprintf(MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH)" ));
194+ }
195+ }
196+
197+ const char *command;
198+ if (expiration) command= (ptr->flags .support_cas ? " gats " : " gat " );
199+ else command= (ptr->flags .support_cas ? " gets " : " get " );
200+
184201 struct libmemcached_io_vector_st vector[]=
185202 {
186203 { strlen (command), command },
204+ { (size_t )expiration_buffer_length, expiration_buffer },
187205 { memcached_array_size (ptr->_namespace ), memcached_array_string (ptr->_namespace ) },
188206 { key_length, key },
189207 { 2 , " \r\n " }
190208 };
191209
192- rc= memcached_vdo (instance, vector, 4 , true );
210+ rc= memcached_vdo (instance, vector, 5 , true );
193211 if (rc != MEMCACHED_SUCCESS) {
194212 memcached_set_error (*ptr, rc, MEMCACHED_AT);
195213 }
@@ -462,13 +480,14 @@ static memcached_return_t binary_mget_by_key(memcached_st *ptr,
462480 What happens if no servers exist?
463481*/
464482
465- char *memcached_get_by_key (memcached_st *ptr,
466- const char *group_key,
467- size_t group_key_length,
468- const char *key, size_t key_length,
469- size_t *value_length,
470- uint32_t *flags,
471- memcached_return_t *error)
483+ static char *memcached_get_by_key (memcached_st *ptr,
484+ const char *group_key,
485+ size_t group_key_length,
486+ const char *key, size_t key_length,
487+ time_t *expiration,
488+ size_t *value_length,
489+ uint32_t *flags,
490+ memcached_return_t *error)
472491{
473492 arcus_server_check_for_update (ptr);
474493
@@ -510,12 +529,17 @@ char *memcached_get_by_key(memcached_st *ptr,
510529 /* Request the key */
511530 if (ptr->flags .binary_protocol )
512531 {
532+ if (expiration)
533+ {
534+ *error= MEMCACHED_NOT_SUPPORTED;
535+ return NULL ;
536+ }
513537 *error= binary_mget_by_key (ptr, master_server_key, is_group_key_set,
514538 (const char * const *)&key, &key_length, 1 , false );
515539 }
516540 else
517541 {
518- *error= ascii_get_by_key (ptr, master_server_key, is_group_key_set, key, key_length);
542+ *error= ascii_get_by_key (ptr, master_server_key, is_group_key_set, key, key_length, expiration );
519543 }
520544
521545 assert_msg (ptr->query_id >= query_id +1 , " Programmer error, the query_id was not incremented." );
@@ -614,6 +638,18 @@ char *memcached_get_by_key(memcached_st *ptr,
614638 return value;
615639}
616640
641+ char *memcached_get_by_key (memcached_st *ptr,
642+ const char *group_key,
643+ size_t group_key_length,
644+ const char *key, size_t key_length,
645+ size_t *value_length,
646+ uint32_t *flags,
647+ memcached_return_t *error)
648+ {
649+ return memcached_get_by_key (ptr, group_key, group_key_length, key, key_length,
650+ NULL , value_length, flags, error);
651+ }
652+
617653char *memcached_get (memcached_st *ptr, const char *key,
618654 size_t key_length,
619655 size_t *value_length,
@@ -624,6 +660,28 @@ char *memcached_get(memcached_st *ptr, const char *key,
624660 flags, error);
625661}
626662
663+ char *memcached_gat_by_key (memcached_st *ptr,
664+ const char *group_key,
665+ size_t group_key_length,
666+ const char *key, size_t key_length,
667+ time_t expiration,
668+ size_t *value_length,
669+ uint32_t *flags,
670+ memcached_return_t *error)
671+ {
672+ return memcached_get_by_key (ptr, group_key, group_key_length, key, key_length,
673+ &expiration, value_length, flags, error);
674+ }
675+
676+ char *memcached_gat (memcached_st *ptr, const char *key,
677+ size_t key_length, time_t expiration,
678+ size_t *value_length, uint32_t *flags,
679+ memcached_return_t *error)
680+ {
681+ return memcached_gat_by_key (ptr, NULL , 0 , key, key_length, expiration,
682+ value_length, flags, error);
683+ }
684+
627685memcached_return_t memcached_mget_by_key (memcached_st *ptr,
628686 const char *group_key,
629687 size_t group_key_length,
0 commit comments