public String pipelineRead ( String key , int max_pipe_keys , int min_pipe_keys ) throws Exception { int pipe_keys = randomGenerator . nextInt ( max_pipe_keys ) ; pipe_keys = Math . max ( min_pipe_keys , pipe_keys ) ; DynoJedisPipeline pipeline = this . jedisClient . get ( ) . pipelined ( ) ; Map < String , Response < String > > responses = new HashMap <> ( ) ; for ( int n = 0 ; n < pipe_keys ; ++ n ) { String nth_key = key + "_" + n ; // NOTE: Dyno Jedis works on only one key, so we always use the same // key in every get operation Response < String > resp = pipeline . get ( key ) ; // We however use the nth key as the key in the hashmap to check // individual response on every operation. responses . put ( nth_key , resp ) ; } pipeline . sync ( ) ; for ( int n = 0 ; n < pipe_keys ; ++ n ) { String nth_key = key + "_" + n ; Response < String > resp = responses . get ( nth_key ) ; if ( resp == null || resp . get ( ) == null ) { logger . info ( "Cache Miss on pipelined read: key:" + key ) ; return null ; } else { if ( resp . get ( ) . startsWith ( "ERR" ) ) { throw new Exception ( String . format ( "DynoJedisPipeline: error %s" , resp . get ( ) ) ) ; } if ( ! isValidResponse ( key , resp . get ( ) ) ) { throw new Exception ( String . format ( "DynoJedisPipeline: pipeline read: value %s does not contain key %s" , resp . get ( ) , key ) ) ; } } } return "OK" ; }
This is the pipelined version of the reads