@@ -177,6 +177,7 @@ static zend_function_entry redis_functions[] = {
177177 PHP_ME (Redis , object , NULL , ZEND_ACC_PUBLIC )
178178 PHP_ME (Redis , bitop , NULL , ZEND_ACC_PUBLIC )
179179 PHP_ME (Redis , bitcount , NULL , ZEND_ACC_PUBLIC )
180+ PHP_ME (Redis , bitpos , NULL , ZEND_ACC_PUBLIC )
180181
181182 /* 1.1 */
182183 PHP_ME (Redis , mset , NULL , ZEND_ACC_PUBLIC )
@@ -820,6 +821,59 @@ PHP_METHOD(Redis, bitcount)
820821}
821822/* }}} */
822823
824+ /* {{{ proto integer Redis::bitpos(string key, int bit, [int start], [int end]) */
825+ PHP_METHOD (Redis , bitpos )
826+ {
827+ zval * object ;
828+ RedisSock * redis_sock ;
829+ char * key , * cmd ;
830+ int key_len , cmd_len , argc , key_free = 0 ;
831+ long bit , start , end ;
832+
833+ argc = ZEND_NUM_ARGS ();
834+
835+ if (zend_parse_method_parameters (argc TSRMLS_CC , getThis (), "Osl|ll" ,
836+ & object , redis_ce , & key , & key_len , & bit ,
837+ & start , & end )== FAILURE )
838+ {
839+ RETURN_FALSE ;
840+ }
841+
842+ if (redis_sock_get (object , & redis_sock TSRMLS_CC , 0 ) < 0 ) {
843+ RETURN_FALSE ;
844+ }
845+
846+ // We can prevalidate the first argument
847+ if (bit != 0 && bit != 1 ) {
848+ RETURN_FALSE ;
849+ }
850+
851+ // Prefix our key
852+ key_free = redis_key_prefix (redis_sock , & key , & key_len TSRMLS_CC );
853+
854+ // Various command semantics
855+ if (argc == 2 ) {
856+ cmd_len = redis_cmd_format_static (& cmd , "BITPOS" , "sd" , key , key_len ,
857+ bit );
858+ } else if (argc == 3 ) {
859+ cmd_len = redis_cmd_format_static (& cmd , "BITPOS" , "sdd" , key , key_len ,
860+ bit , start );
861+ } else {
862+ cmd_len = redis_cmd_format_static (& cmd , "BITPOS" , "sddd" , key , key_len ,
863+ bit , start , end );
864+ }
865+
866+ // Free our key if it was prefixed
867+ if (key_free ) efree (key );
868+
869+ REDIS_PROCESS_REQUEST (redis_sock , cmd , cmd_len );
870+ IF_ATOMIC () {
871+ redis_long_response (INTERNAL_FUNCTION_PARAM_PASSTHRU , redis_sock , NULL , NULL );
872+ }
873+ REDIS_PROCESS_RESPONSE (redis_long_response );
874+ }
875+ /* }}} */
876+
823877/* {{{ proto boolean Redis::close()
824878 */
825879PHP_METHOD (Redis , close )
0 commit comments