<s> import mock <EOL> import os <EOL> import time <EOL> import uuid <EOL> from tornado import testing <EOL> import tredis <EOL> from tredis import exceptions <EOL> from . import base <EOL> class KeyCommandTests ( base . AsyncTestCase ) : <EOL> @ testing . gen_test <EOL> def test_delete ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_delete_multi ( self ) : <EOL> key1 , key2 , value = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . expiring_set ( key1 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . expiring_set ( key2 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . delete ( key1 , key2 ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_delete_missing_key ( self ) : <EOL> key1 , key2 , value = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . expiring_set ( key1 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . expiring_set ( key2 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . delete ( key1 , key2 , <EOL> self . uuid4 ( ) ) <EOL> self . assertEqual ( result , <NUM_LIT:2> ) <EOL> @ testing . gen_test <EOL> def test_dump_and_restore ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> dump_value = yield self . client . dump ( key ) <EOL> self . assertIn ( value , dump_value ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . restore ( key , <NUM_LIT:10> , dump_value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . get ( key ) <EOL> self . assertEqual ( result , value ) <EOL> @ testing . gen_test <EOL> def test_dump_and_restore_with_replace ( self ) : <EOL> key , value1 , value2 = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . expiring_set ( key , value1 ) <EOL> self . assertTrue ( result ) <EOL> dump_value = yield self . client . dump ( key ) <EOL> self . assertIn ( value1 , dump_value ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . expiring_set ( key , value2 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . get ( key ) <EOL> self . assertEqual ( result , value2 ) <EOL> result = yield self . client . restore ( key , <NUM_LIT:10> , dump_value , True ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . get ( key ) <EOL> self . assertEqual ( result , value1 ) <EOL> @ testing . gen_test <EOL> def test_dump_and_restore_without_replace ( self ) : <EOL> key , value1 , value2 = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . expiring_set ( key , value1 ) <EOL> self . assertTrue ( result ) <EOL> dump_value = yield self . client . dump ( key ) <EOL> self . assertIn ( value1 , dump_value ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . expiring_set ( key , value2 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . get ( key ) <EOL> self . assertEqual ( result , value2 ) <EOL> with self . assertRaises ( exceptions . RedisError ) : <EOL> yield self . client . restore ( key , <NUM_LIT:10> , dump_value ) <EOL> @ testing . gen_test <EOL> def test_dump_with_invalid_key ( self ) : <EOL> key = self . uuid4 ( ) <EOL> result = yield self . client . dump ( key ) <EOL> self . assertIsNone ( result ) <EOL> @ testing . gen_test <EOL> def test_expire_and_ttl ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> ttl = <NUM_LIT:5> <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . expire ( key , ttl ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . ttl ( key ) <EOL> self . assertAlmostEqual ( result , ttl ) <EOL> @ testing . gen_test <EOL> def test_expire_with_error ( self ) : <EOL> with self . assertRaises ( exceptions . RedisError ) : <EOL> yield self . client . expire ( self . uuid4 ( ) , '<STR_LIT:abc>' ) <EOL> @ testing . gen_test <EOL> def test_expireat_and_ttl ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> timestamp = int ( time . time ( ) ) + <NUM_LIT:5> <EOL> result = yield self . client . expireat ( key , timestamp ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . ttl ( key ) <EOL> self . assertLessEqual ( result , <NUM_LIT:5> ) <EOL> self . assertGreater ( result , <NUM_LIT:0> ) <EOL> @ testing . gen_test <EOL> def test_expireat_with_error ( self ) : <EOL> with self . assertRaises ( exceptions . RedisError ) : <EOL> yield self . client . expireat ( self . uuid4 ( ) , '<STR_LIT:abc>' ) <EOL> @ testing . gen_test <EOL> def test_exists_single ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . exists ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_exists_none ( self ) : <EOL> key = self . uuid4 ( ) <EOL> result = yield self . client . exists ( key ) <EOL> self . assertFalse ( result ) <EOL> @ testing . gen_test <EOL> def test_keys ( self ) : <EOL> yield self . client . select ( <NUM_LIT:3> ) <EOL> prefix = '<STR_LIT>' <EOL> keys = [ '<STR_LIT>' . format ( prefix , str ( uuid . uuid4 ( ) ) ) . encode ( '<STR_LIT:ascii>' ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:10> ) ] <EOL> for key in keys : <EOL> yield self . expiring_set ( key , str ( uuid . uuid4 ( ) ) ) <EOL> result = yield self . client . keys ( '<STR_LIT>' . format ( prefix ) ) <EOL> self . assertListEqual ( sorted ( result ) , sorted ( keys ) ) <EOL> @ testing . gen_test <EOL> def test_move ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> response = yield self . client . select ( <NUM_LIT:2> ) <EOL> self . assertTrue ( response ) <EOL> response = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( response ) <EOL> response = yield self . client . move ( key , <NUM_LIT:1> ) <EOL> self . assertTrue ( response ) <EOL> response = yield self . client . select ( <NUM_LIT:1> ) <EOL> self . assertTrue ( response ) <EOL> response = yield self . client . get ( key ) <EOL> self . assertEqual ( response , value ) <EOL> @ testing . gen_test <EOL> def test_object_encoding ( self ) : <EOL> key , value1 , value2 = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . client . sadd ( key , value1 , value2 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . object_encoding ( key ) <EOL> self . assertEqual ( result , b'<STR_LIT>' ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_object_idle_time ( self ) : <EOL> key , value1 , value2 = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . client . sadd ( key , value1 , value2 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . object_idle_time ( key ) <EOL> self . assertEqual ( result , <NUM_LIT:0> ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_object_refcount ( self ) : <EOL> key = self . uuid4 ( ) <EOL> for value in self . uuid4 ( <NUM_LIT:3> ) : <EOL> result = yield self . client . _execute ( [ b'<STR_LIT>' , key , b'<STR_LIT:1>' , value ] ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . object_refcount ( key ) <EOL> self . assertEqual ( result , <NUM_LIT:1> ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_persist ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . expire ( key , <NUM_LIT:10> ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . persist ( key ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . ttl ( key ) <EOL> self . assertEqual ( result , - <NUM_LIT:1> ) <EOL> @ testing . gen_test <EOL> def test_pexpire_and_ttl ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . pexpire ( key , <NUM_LIT> ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . ttl ( key ) <EOL> self . assertAlmostEqual ( result , <NUM_LIT:5> ) <EOL> @ testing . gen_test <EOL> def test_pexpire_with_error ( self ) : <EOL> with self . assertRaises ( exceptions . RedisError ) : <EOL> yield self . client . pexpire ( self . uuid4 ( ) , '<STR_LIT:abc>' ) <EOL> @ testing . gen_test <EOL> def test_pexpireat_and_ttl ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> timestamp = ( int ( time . time ( ) ) + <NUM_LIT:5> ) * <NUM_LIT:1000> <EOL> result = yield self . client . pexpireat ( key , timestamp ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . ttl ( key ) <EOL> self . assertLessEqual ( result , <NUM_LIT:5> ) <EOL> self . assertGreater ( result , <NUM_LIT:0> ) <EOL> @ testing . gen_test <EOL> def test_pexpireat_with_error ( self ) : <EOL> with self . assertRaises ( exceptions . RedisError ) : <EOL> yield self . client . pexpireat ( self . uuid4 ( ) , '<STR_LIT:abc>' ) <EOL> @ testing . gen_test <EOL> def test_pttl ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . pexpire ( key , <NUM_LIT> ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . pttl ( key ) <EOL> self . assertGreater ( result , <NUM_LIT:1000> ) <EOL> self . assertLessEqual ( result , <NUM_LIT> ) <EOL> @ testing . gen_test <EOL> def test_randomkey ( self ) : <EOL> yield self . client . select ( <NUM_LIT:4> ) <EOL> keys = self . uuid4 ( <NUM_LIT:10> ) <EOL> for key in list ( keys ) : <EOL> yield self . expiring_set ( key , str ( uuid . uuid4 ( ) ) ) <EOL> result = yield self . client . randomkey ( ) <EOL> self . assertIn ( result , keys ) <EOL> @ testing . gen_test <EOL> def test_rename ( self ) : <EOL> key1 , key2 , value = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . expiring_set ( key1 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . rename ( key1 , key2 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . get ( key2 ) <EOL> self . assertEqual ( result , value ) <EOL> @ testing . gen_test <EOL> def test_renamenx ( self ) : <EOL> key1 , key2 , value = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . expiring_set ( key1 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . get ( key2 ) <EOL> self . assertIsNone ( result ) <EOL> result = yield self . client . renamenx ( key1 , key2 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . get ( key2 ) <EOL> self . assertEqual ( result , value ) <EOL> @ testing . gen_test <EOL> def test_renamenx_failure ( self ) : <EOL> key1 , key2 , value = self . uuid4 ( <NUM_LIT:3> ) <EOL> result = yield self . expiring_set ( key1 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . expiring_set ( key2 , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . renamenx ( key1 , key2 ) <EOL> self . assertFalse ( result ) <EOL> @ testing . gen_test <EOL> def test_scan ( self ) : <EOL> yield self . client . select ( <NUM_LIT:5> ) <EOL> key1 , key2 , key3 , value = self . uuid4 ( <NUM_LIT:4> ) <EOL> keys = [ key1 , key2 , key3 ] <EOL> for key in keys : <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> cursor , result = yield self . client . scan ( <NUM_LIT:0> ) <EOL> self . assertListEqual ( sorted ( result ) , sorted ( keys ) ) <EOL> self . assertEqual ( cursor , <NUM_LIT:0> ) <EOL> for key in keys : <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_scan_with_pattern ( self ) : <EOL> yield self . client . select ( <NUM_LIT:5> ) <EOL> key1 , key2 , key3 , value = self . uuid4 ( <NUM_LIT:4> ) <EOL> keys = [ key1 , key2 , key3 ] <EOL> for key in keys : <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> cursor , result = yield self . client . scan ( <NUM_LIT:0> , '<STR_LIT:*>' ) <EOL> self . assertListEqual ( sorted ( result ) , sorted ( keys ) ) <EOL> self . assertEqual ( cursor , <NUM_LIT:0> ) <EOL> for key in keys : <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_scan_with_pattern_and_count ( self ) : <EOL> yield self . client . select ( <NUM_LIT:5> ) <EOL> key1 , key2 , key3 , value = self . uuid4 ( <NUM_LIT:4> ) <EOL> keys = [ key1 , key2 , key3 ] <EOL> for key in keys : <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> cursor , result = yield self . client . scan ( <NUM_LIT:0> , '<STR_LIT:*>' , <NUM_LIT:10> ) <EOL> self . assertListEqual ( sorted ( result ) , sorted ( keys ) ) <EOL> self . assertEqual ( cursor , <NUM_LIT:0> ) <EOL> for key in keys : <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_scan_with_error ( self ) : <EOL> key = self . uuid4 ( ) <EOL> self . _execute_result = exceptions . RedisError ( '<STR_LIT>' ) <EOL> with mock . patch . object ( self . client , '<STR_LIT>' , self . _execute ) : <EOL> with self . assertRaises ( exceptions . RedisError ) : <EOL> yield self . client . scan ( key , <NUM_LIT:0> ) <EOL> @ testing . gen_test <EOL> def test_sort_invalid_order ( self ) : <EOL> key = self . uuid4 ( ) <EOL> with self . assertRaises ( ValueError ) : <EOL> yield self . client . sort ( key , alpha = True , order = '<STR_LIT>' ) <EOL> @ testing . gen_test <EOL> def test_sort_numeric ( self ) : <EOL> key = self . uuid4 ( ) <EOL> result = yield self . client . sadd ( key , <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT:200> ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . sort ( key ) <EOL> self . assertListEqual ( result , [ b'<STR_LIT:100>' , b'<STR_LIT>' , b'<STR_LIT>' ] ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_sort_alpha_asc ( self ) : <EOL> key , value1 , value2 , value3 = self . uuid4 ( <NUM_LIT:4> ) <EOL> result = yield self . client . sadd ( key , value1 , value2 , value3 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . sort ( key , alpha = True ) <EOL> self . assertListEqual ( result , sorted ( [ value1 , value2 , value3 ] ) ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_sort_alpha_desc ( self ) : <EOL> key , value1 , value2 , value3 = self . uuid4 ( <NUM_LIT:4> ) <EOL> result = yield self . client . sadd ( key , value1 , value2 , value3 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . sort ( key , alpha = True , order = '<STR_LIT>' ) <EOL> self . assertListEqual ( result , sorted ( [ value1 , value2 , value3 ] , <EOL> reverse = True ) ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_sort_alpha_limit_offset ( self ) : <EOL> key , value1 , value2 , value3 = self . uuid4 ( <NUM_LIT:4> ) <EOL> result = yield self . client . sadd ( key , value1 , value2 , value3 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . sort ( key , limit = <NUM_LIT:2> , offset = <NUM_LIT:1> , alpha = True ) <EOL> self . assertListEqual ( result , sorted ( [ value1 , value2 , value3 ] ) [ <NUM_LIT:1> : ] ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_sort_alpha_asc_and_store ( self ) : <EOL> key1 , key2 , value1 , value2 , value3 = self . uuid4 ( <NUM_LIT:5> ) <EOL> result = yield self . client . sadd ( key1 , value1 , value2 , value3 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . sort ( key1 , alpha = True , store_as = key2 ) <EOL> self . assertEqual ( result , <NUM_LIT:3> ) <EOL> result = yield self . client . type ( key2 ) <EOL> result = yield self . client . _execute ( [ b'<STR_LIT>' , key2 , <NUM_LIT:0> , <NUM_LIT:3> ] ) <EOL> self . assertListEqual ( result , sorted ( [ value1 , value2 , value3 ] ) ) <EOL> result = yield self . client . delete ( key1 ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . delete ( key2 ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_sort_by ( self ) : <EOL> key , value1 , value2 , value3 = self . uuid4 ( <NUM_LIT:4> ) <EOL> values = [ value1 , value2 , value3 ] <EOL> result = yield self . client . sadd ( key , value1 , value2 , value3 ) <EOL> self . assertTrue ( result ) <EOL> expectation = [ ] <EOL> for index , value in enumerate ( values ) : <EOL> weight_key = '<STR_LIT>' . format ( value . decode ( '<STR_LIT:utf-8>' ) ) <EOL> result = yield self . expiring_set ( weight_key , index ) <EOL> self . assertTrue ( result ) <EOL> expectation . append ( value ) <EOL> result = yield self . client . sort ( key , by = '<STR_LIT>' ) <EOL> self . assertListEqual ( result , expectation ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_sort_by_with_external ( self ) : <EOL> key , value1 , value2 , value3 = self . uuid4 ( <NUM_LIT:4> ) <EOL> values = [ value1 , value2 , value3 ] <EOL> result = yield self . client . sadd ( key , value1 , value2 , value3 ) <EOL> self . assertTrue ( result ) <EOL> expectation = [ ] <EOL> for index , value in enumerate ( values ) : <EOL> weight_key = '<STR_LIT>' . format ( value . decode ( '<STR_LIT:utf-8>' ) ) <EOL> result = yield self . expiring_set ( weight_key , index ) <EOL> self . assertTrue ( result ) <EOL> ext_key = '<STR_LIT>' . format ( value . decode ( '<STR_LIT:utf-8>' ) ) <EOL> ext_val = '<STR_LIT>' . format ( index ) . encode ( '<STR_LIT:utf-8>' ) <EOL> result = yield self . expiring_set ( ext_key , ext_val ) <EOL> self . assertTrue ( result ) <EOL> expectation . append ( ext_val ) <EOL> result = yield self . client . sort ( key , by = '<STR_LIT>' , <EOL> external = '<STR_LIT>' ) <EOL> self . assertListEqual ( result , expectation ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_sort_by_with_externals ( self ) : <EOL> key , value1 , value2 , value3 = self . uuid4 ( <NUM_LIT:4> ) <EOL> values = [ value1 , value2 , value3 ] <EOL> result = yield self . client . sadd ( key , value1 , value2 , value3 ) <EOL> self . assertTrue ( result ) <EOL> expectation = [ ] <EOL> for index , value in enumerate ( values ) : <EOL> weight_key = '<STR_LIT>' . format ( value . decode ( '<STR_LIT:utf-8>' ) ) <EOL> result = yield self . expiring_set ( weight_key , index ) <EOL> self . assertTrue ( result ) <EOL> ext_key = '<STR_LIT>' . format ( value . decode ( '<STR_LIT:utf-8>' ) ) <EOL> ext_val = '<STR_LIT>' . format ( index ) . encode ( '<STR_LIT:utf-8>' ) <EOL> result = yield self . expiring_set ( ext_key , ext_val ) <EOL> self . assertTrue ( result ) <EOL> expectation . append ( ext_val ) <EOL> ext_key = '<STR_LIT>' . format ( value . decode ( '<STR_LIT:utf-8>' ) ) <EOL> ext_val = '<STR_LIT>' . format ( index ) . encode ( '<STR_LIT:utf-8>' ) <EOL> result = yield self . expiring_set ( ext_key , ext_val ) <EOL> self . assertTrue ( result ) <EOL> expectation . append ( ext_val ) <EOL> result = yield self . client . sort ( key , by = '<STR_LIT>' , <EOL> external = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertListEqual ( result , expectation ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_type_string ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . type ( key ) <EOL> self . assertEqual ( result , b'<STR_LIT:string>' ) <EOL> @ testing . gen_test <EOL> def test_type_set ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . client . sadd ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . type ( key ) <EOL> self . assertEqual ( result , b'<STR_LIT>' ) <EOL> result = yield self . client . delete ( key ) <EOL> self . assertTrue ( result ) <EOL> @ testing . gen_test <EOL> def test_wait ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . wait ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> self . assertEqual ( result , <NUM_LIT:0> ) <EOL> class MigrationTests ( base . AsyncTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( MigrationTests , self ) . setUp ( ) <EOL> self . redis_host = os . getenv ( '<STR_LIT>' , '<STR_LIT:localhost>' ) <EOL> self . redis2_host = os . getenv ( '<STR_LIT>' , '<STR_LIT:localhost>' ) <EOL> self . redis2_port = int ( os . getenv ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ testing . gen_test <EOL> def test_migrate ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . migrate ( self . redis2_host , <NUM_LIT> , key , <NUM_LIT:10> , <EOL> <NUM_LIT> ) <EOL> self . assertTrue ( result ) <EOL> client = tredis . RedisClient ( self . redis_host , self . redis2_port , <NUM_LIT:10> ) <EOL> response = yield client . get ( key ) <EOL> self . assertEqual ( response , value ) <EOL> result = yield self . client . get ( key ) <EOL> self . assertIsNone ( result ) <EOL> @ testing . gen_test <EOL> def test_migrate_copy ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . migrate ( self . redis2_host , <NUM_LIT> , key , <NUM_LIT:10> , <EOL> <NUM_LIT> , copy = True ) <EOL> self . assertTrue ( result ) <EOL> client = tredis . RedisClient ( self . redis_host , self . redis2_port , <NUM_LIT:10> ) <EOL> result = yield client . get ( key ) <EOL> self . assertEqual ( result , value ) <EOL> result = yield self . client . get ( key ) <EOL> self . assertEqual ( result , value ) <EOL> @ testing . gen_test <EOL> def test_migrate_exists ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> client = tredis . RedisClient ( self . redis_host , self . redis2_port , <NUM_LIT:10> ) <EOL> result = yield client . set ( key , value , <NUM_LIT:10> ) <EOL> self . assertTrue ( result ) <EOL> with self . assertRaises ( exceptions . RedisError ) : <EOL> yield self . client . migrate ( self . redis2_host , <NUM_LIT> , key , <NUM_LIT:10> , <NUM_LIT> ) <EOL> @ testing . gen_test <EOL> def test_migrate_replace ( self ) : <EOL> key , value = self . uuid4 ( <NUM_LIT:2> ) <EOL> result = yield self . expiring_set ( key , value ) <EOL> self . assertTrue ( result ) <EOL> client = tredis . RedisClient ( self . redis_host , self . redis2_port , <NUM_LIT:10> ) <EOL> result = yield client . set ( key , value , <NUM_LIT:10> ) <EOL> self . assertTrue ( result ) <EOL> result = yield self . client . migrate ( self . redis2_host , <NUM_LIT> , <EOL> key , <NUM_LIT:10> , <NUM_LIT> , replace = True ) <EOL> self . assertTrue ( result ) <EOL> result = yield client . get ( key ) <EOL> self . assertEqual ( result , value ) <EOL> result = yield self . client . get ( key ) <EOL> self . assertIsNone ( result ) </s>
