<s> import math <EOL> from nose . tools import ( assert_equals , assert_dict_equal , assert_not_equals , <EOL> assert_tuple_equal , assert_true , assert_false , <EOL> assert_list_equal , assert_is_none , assert_items_equal , <EOL> assert_almost_equal , raises ) <EOL> import ssdb <EOL> from ssdb . connection import Connection , ConnectionPool , BlockingConnectionPool <EOL> from ssdb . client import SSDB <EOL> class TestClient ( object ) : <EOL> def setUp ( self ) : <EOL> pool = BlockingConnectionPool ( <EOL> connection_class = Connection , <EOL> max_connections = <NUM_LIT:2> , <EOL> timeout = <NUM_LIT:5> , <EOL> host = '<STR_LIT:127.0.0.1>' , <EOL> port = <NUM_LIT> ) <EOL> self . client = SSDB ( connection_pool = pool ) <EOL> print ( '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> print ( '<STR_LIT>' ) <EOL> def test_get ( self ) : <EOL> a = self . client . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT>' ) <EOL> c = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( c ) <EOL> d = self . client . get ( '<STR_LIT>' ) <EOL> assert_is_none ( d ) <EOL> def test_set ( self ) : <EOL> a = self . client . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> c = self . client . exists ( '<STR_LIT>' ) <EOL> assert_true ( c ) <EOL> b = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( b ) <EOL> c = self . client . exists ( '<STR_LIT>' ) <EOL> assert_false ( c ) <EOL> def test_getset ( self ) : <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> a = self . client . getset ( '<STR_LIT>' , '<STR_LIT:abc>' ) <EOL> assert_is_none ( a ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT:abc>' ) <EOL> c = self . client . set ( '<STR_LIT>' , '<STR_LIT:abc>' ) <EOL> assert_true ( c ) <EOL> d = self . client . getset ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( d , '<STR_LIT:abc>' ) <EOL> e = self . client . getset ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( e , '<STR_LIT>' ) <EOL> f = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( f ) <EOL> g = self . client . exists ( '<STR_LIT>' ) <EOL> assert_false ( g ) <EOL> def test_setnx ( self ) : <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> a = self . client . setnx ( '<STR_LIT>' , '<STR_LIT:abc>' ) <EOL> assert_true ( a ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT:abc>' ) <EOL> c = self . client . setnx ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_false ( c ) <EOL> f = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( f ) <EOL> g = self . client . exists ( '<STR_LIT>' ) <EOL> assert_false ( g ) <EOL> def test_bit ( self ) : <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> self . client . set ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> a = self . client . countbit ( '<STR_LIT>' ) <EOL> assert_equals ( a , <NUM_LIT:3> ) <EOL> a = self . client . setbit ( '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> assert_false ( a ) <EOL> a = self . client . getbit ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> assert_true ( a ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT:3>' ) <EOL> c = self . client . setbit ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> assert_false ( c ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT>' ) <EOL> c = self . client . setbit ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> assert_true ( c ) <EOL> c = self . client . getbit ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> assert_false ( c ) <EOL> c = self . client . set ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c = self . client . countbit ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> assert_equals ( c , <NUM_LIT:3> ) <EOL> c = self . client . countbit ( '<STR_LIT>' , <NUM_LIT:3> , - <NUM_LIT:3> ) <EOL> assert_equals ( c , <NUM_LIT:16> ) <EOL> f = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( f ) <EOL> def test_str ( self ) : <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> self . client . set ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> a = self . client . substr ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> assert_equals ( a , "<STR_LIT>" ) <EOL> a = self . client . substr ( '<STR_LIT>' , - <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> assert_equals ( a , "<STR_LIT>" ) <EOL> a = self . client . substr ( '<STR_LIT>' , <NUM_LIT:1> , - <NUM_LIT:1> ) <EOL> assert_equals ( a , "<STR_LIT>" ) <EOL> a = self . client . strlen ( '<STR_LIT>' ) <EOL> assert_equals ( a , <NUM_LIT:11> ) <EOL> f = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( f ) <EOL> @ raises ( ValueError ) <EOL> def test_incr ( self ) : <EOL> a = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> a = self . client . set ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_true ( a ) <EOL> a = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( a , '<STR_LIT>' ) <EOL> a = self . client . incr ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> assert_equals ( a , <NUM_LIT:12> ) <EOL> a = self . client . incr ( '<STR_LIT>' , - <NUM_LIT:2> ) <EOL> assert_equals ( a , <NUM_LIT:10> ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( int ( b ) , a ) <EOL> a = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> c = self . client . incr ( '<STR_LIT>' , '<STR_LIT:abc>' ) <EOL> @ raises ( ValueError ) <EOL> def test_decr ( self ) : <EOL> a = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> a = self . client . set ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_true ( a ) <EOL> a = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( a , '<STR_LIT>' ) <EOL> a = self . client . decr ( '<STR_LIT>' , <NUM_LIT:3> ) <EOL> assert_equals ( a , <NUM_LIT:7> ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( int ( b ) , a ) <EOL> a = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> c = self . client . decr ( '<STR_LIT>' , - <NUM_LIT:2> ) <EOL> def test_multi_set ( self ) : <EOL> params = { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> } <EOL> a = self . client . multi_set ( ** params ) <EOL> assert_equals ( a , <NUM_LIT:4> ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT:1>' ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT:2>' ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT:3>' ) <EOL> b = self . client . get ( '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT:4>' ) <EOL> d = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> d = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> d = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> d = self . client . delete ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> def test_multi_get ( self ) : <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> a = self . client . multi_set ( ** params ) <EOL> assert_equals ( a , len ( params ) ) <EOL> r = self . client . multi_get ( * params . keys ( ) ) <EOL> assert_dict_equal ( r , params ) <EOL> d = self . client . multi_del ( * params . keys ( ) ) <EOL> assert_equals ( d , len ( params ) ) <EOL> def test_keys ( self ) : <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> a = self . client . multi_set ( ** params ) <EOL> assert_equals ( a , len ( params ) ) <EOL> b = self . client . keys ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_items_equal ( b , params . keys ( ) ) <EOL> d = self . client . multi_del ( * params . keys ( ) ) <EOL> assert_equals ( d , len ( params ) ) <EOL> def test_scan ( self ) : <EOL> keys = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> values = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> params = { } <EOL> for i in range ( len ( keys ) ) : <EOL> params [ keys [ i ] ] = values [ i ] <EOL> a = self . client . multi_set ( ** params ) <EOL> assert_equals ( a , len ( params ) ) <EOL> b = self . client . scan ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_dict_equal ( b , params ) <EOL> index = <NUM_LIT:0> <EOL> for k , v in b . items ( ) : <EOL> assert_equals ( k , keys [ index ] ) <EOL> assert_equals ( v , values [ index ] ) <EOL> index += <NUM_LIT:1> <EOL> d = self . client . multi_del ( * params . keys ( ) ) <EOL> assert_equals ( d , len ( params ) ) <EOL> def test_rscan ( self ) : <EOL> keys = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> values = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> params = { } <EOL> for i in range ( len ( keys ) ) : <EOL> params [ keys [ i ] ] = values [ i ] <EOL> a = self . client . multi_set ( ** params ) <EOL> assert_equals ( a , len ( params ) ) <EOL> b = self . client . rscan ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_dict_equal ( b , params ) <EOL> index = <NUM_LIT:0> <EOL> c = len ( keys ) <EOL> for k , v in b . items ( ) : <EOL> assert_equals ( k , keys [ c - index - <NUM_LIT:1> ] ) <EOL> assert_equals ( v , values [ c - index - <NUM_LIT:1> ] ) <EOL> index += <NUM_LIT:1> <EOL> d = self . client . multi_del ( * params . keys ( ) ) <EOL> assert_equals ( d , len ( params ) ) <EOL> def test_hset ( self ) : <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> b = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT>' ) <EOL> b = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( b , '<STR_LIT>' ) <EOL> d = self . client . hclear ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> def test_hdel ( self ) : <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> e = self . client . hexists ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( e ) <EOL> e = self . client . hexists ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( e ) <EOL> b = self . client . hexists ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_false ( b ) <EOL> b = self . client . hdel ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( b ) <EOL> b = self . client . hdel ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_true ( b ) <EOL> b = self . client . hexists ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_false ( b ) <EOL> c = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_is_none ( c ) <EOL> b = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_is_none ( c ) <EOL> def test_hincr ( self ) : <EOL> self . client . hclear ( '<STR_LIT>' ) <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:100> ) <EOL> assert_true ( a ) <EOL> b = self . client . hincr ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( b , <NUM_LIT> ) <EOL> b = self . client . hincr ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( b , <NUM_LIT> ) <EOL> b = self . client . hdecr ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( b , <NUM_LIT> ) <EOL> b = self . client . hdecr ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( b , <NUM_LIT:100> ) <EOL> d = self . client . hclear ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> def test_hsize ( self ) : <EOL> b = self . client . hsize ( '<STR_LIT>' ) <EOL> assert_equals ( b , <NUM_LIT:0> ) <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT:b>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> a = self . client . hset ( '<STR_LIT>' , '<STR_LIT:c>' , '<STR_LIT>' ) <EOL> assert_true ( a ) <EOL> b = self . client . hsize ( '<STR_LIT>' ) <EOL> assert_equals ( b , <NUM_LIT:3> ) <EOL> d = self . client . hclear ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> def test_hgetall ( self ) : <EOL> self . client . hclear ( '<STR_LIT>' ) <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> dct = { <EOL> '<STR_LIT:a>' : "<STR_LIT>" , <EOL> '<STR_LIT:b>' : "<STR_LIT>" , <EOL> '<STR_LIT:c>' : "<STR_LIT>" , <EOL> '<STR_LIT:d>' : "<STR_LIT>" <EOL> } <EOL> a = self . client . multi_hset ( '<STR_LIT>' , ** dct ) <EOL> assert_equals ( a , <NUM_LIT:4> ) <EOL> a = self . client . hgetall ( '<STR_LIT>' ) <EOL> assert_dict_equal ( a , dct ) <EOL> b = self . client . delete ( '<STR_LIT>' ) <EOL> d = self . client . hclear ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> def test_hmulti ( self ) : <EOL> params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> a = self . client . multi_hset ( '<STR_LIT>' , ** params ) <EOL> assert_equals ( a , <NUM_LIT:8> ) <EOL> a1 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( a1 , '<STR_LIT>' ) <EOL> b2 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( b2 , '<STR_LIT>' ) <EOL> c3 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( c3 , '<STR_LIT>' ) <EOL> d4 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( d4 , '<STR_LIT>' ) <EOL> e5 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( e5 , '<STR_LIT>' ) <EOL> f6 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( f6 , '<STR_LIT>' ) <EOL> g7 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( g7 , '<STR_LIT>' ) <EOL> h8 = self . client . hget ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( h8 , '<STR_LIT>' ) <EOL> keys = self . client . hkeys ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_items_equal ( keys , params . keys ( ) ) <EOL> kvs = self . client . multi_hget ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_dict_equal ( kvs , { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> } ) <EOL> kvs = self . client . hscan ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_dict_equal ( kvs , params ) <EOL> kvs = self . client . hrscan ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_dict_equal ( kvs , { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> } ) <EOL> r = self . client . multi_hget ( '<STR_LIT>' , * params . keys ( ) ) <EOL> assert_dict_equal ( r , params ) <EOL> d = self . client . multi_hdel ( '<STR_LIT>' , * params . keys ( ) ) <EOL> assert_equals ( d , len ( params ) ) <EOL> def test_hlist ( self ) : <EOL> params = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:a>' : <NUM_LIT:1> , <EOL> '<STR_LIT:b>' : <NUM_LIT:2> , <EOL> '<STR_LIT:c>' : <NUM_LIT:3> , <EOL> '<STR_LIT:d>' : <NUM_LIT:4> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:h>' : <NUM_LIT:11> , <EOL> '<STR_LIT:i>' : <NUM_LIT:12> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:k>' : <NUM_LIT> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:o>' : <NUM_LIT> , <EOL> '<STR_LIT:p>' : <NUM_LIT> , <EOL> '<STR_LIT:q>' : <NUM_LIT> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:r>' : <NUM_LIT> , <EOL> '<STR_LIT:s>' : <NUM_LIT:32> , <EOL> '<STR_LIT:t>' : <NUM_LIT> , <EOL> } , <EOL> } <EOL> for k , v in params . items ( ) : <EOL> a = self . client . hclear ( k ) <EOL> for k , v in params . items ( ) : <EOL> a = self . client . multi_hset ( k , ** v ) <EOL> assert_equals ( a , len ( v ) ) <EOL> c = self . client . hlist ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_items_equal ( c , params . keys ( ) ) <EOL> lst = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for index , item in enumerate ( c ) : <EOL> assert_equals ( item , lst [ index ] ) <EOL> c = self . client . hrlist ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> lst . reverse ( ) <EOL> for index , item in enumerate ( c ) : <EOL> assert_equals ( item , lst [ index ] ) <EOL> for k , v in params . items ( ) : <EOL> a = self . client . hclear ( k ) <EOL> assert_true ( a ) <EOL> def test_zset ( self ) : <EOL> params = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:a>' : <NUM_LIT:1> , <EOL> '<STR_LIT:b>' : <NUM_LIT:2> , <EOL> '<STR_LIT:c>' : <NUM_LIT:3> , <EOL> '<STR_LIT:d>' : <NUM_LIT:4> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:h>' : <NUM_LIT:11> , <EOL> '<STR_LIT:i>' : <NUM_LIT:12> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:k>' : <NUM_LIT> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:o>' : <NUM_LIT> , <EOL> '<STR_LIT:p>' : <NUM_LIT> , <EOL> '<STR_LIT:q>' : <NUM_LIT> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:r>' : <NUM_LIT> , <EOL> '<STR_LIT:s>' : <NUM_LIT:32> , <EOL> '<STR_LIT:t>' : <NUM_LIT> , <EOL> } , <EOL> } <EOL> for k , v in params . items ( ) : <EOL> a = self . client . multi_zset ( k , ** v ) <EOL> assert_equals ( a , len ( v ) ) <EOL> a = self . client . zlist ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_items_equal ( a , params . keys ( ) ) <EOL> a = self . client . zkeys ( '<STR_LIT>' , '<STR_LIT:h>' , <NUM_LIT:11> , <NUM_LIT:20> , <NUM_LIT:10> ) <EOL> zset_b = params [ '<STR_LIT>' ] . copy ( ) <EOL> zset_b . pop ( '<STR_LIT:h>' ) <EOL> assert_items_equal ( a , zset_b . keys ( ) ) <EOL> a = self . client . zscan ( '<STR_LIT>' , '<STR_LIT:a>' , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:10> ) <EOL> zset_a = params [ '<STR_LIT>' ] . copy ( ) <EOL> zset_a . pop ( '<STR_LIT:a>' ) <EOL> zset_a . pop ( '<STR_LIT:d>' ) <EOL> assert_dict_equal ( a , zset_a ) <EOL> a = self . client . zrscan ( '<STR_LIT>' , '<STR_LIT:d>' , <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:10> ) <EOL> zset_a [ '<STR_LIT:a>' ] = params [ '<STR_LIT>' ] [ '<STR_LIT:a>' ] <EOL> assert_dict_equal ( a , zset_a ) <EOL> a = self . client . zrank ( '<STR_LIT>' , '<STR_LIT:a>' ) <EOL> assert_equals ( a , <NUM_LIT:0> ) <EOL> a = self . client . zrank ( '<STR_LIT>' , '<STR_LIT:b>' ) <EOL> assert_equals ( a , <NUM_LIT:1> ) <EOL> a = self . client . zrank ( '<STR_LIT>' , '<STR_LIT:c>' ) <EOL> assert_equals ( a , <NUM_LIT:2> ) <EOL> a = self . client . zrank ( '<STR_LIT>' , '<STR_LIT:d>' ) <EOL> assert_equals ( a , <NUM_LIT:3> ) <EOL> a = self . client . zrrank ( '<STR_LIT>' , '<STR_LIT:d>' ) <EOL> assert_equals ( a , <NUM_LIT:0> ) <EOL> a = self . client . zrrank ( '<STR_LIT>' , '<STR_LIT:c>' ) <EOL> assert_equals ( a , <NUM_LIT:1> ) <EOL> a = self . client . zrrank ( '<STR_LIT>' , '<STR_LIT:b>' ) <EOL> assert_equals ( a , <NUM_LIT:2> ) <EOL> a = self . client . zrrank ( '<STR_LIT>' , '<STR_LIT:a>' ) <EOL> assert_equals ( a , <NUM_LIT:3> ) <EOL> a = self . client . zrange ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> zset_b = params [ '<STR_LIT>' ] . copy ( ) <EOL> zset_b . pop ( '<STR_LIT>' ) <EOL> zset_b . pop ( '<STR_LIT:k>' ) <EOL> assert_dict_equal ( a , zset_b ) <EOL> a = self . client . zrange ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> zset_b = params [ '<STR_LIT>' ] . copy ( ) <EOL> zset_b . pop ( '<STR_LIT:h>' ) <EOL> zset_b . pop ( '<STR_LIT:i>' ) <EOL> assert_dict_equal ( a , zset_b ) <EOL> a = self . client . zrrange ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> zset_b = params [ '<STR_LIT>' ] . copy ( ) <EOL> zset_b . pop ( '<STR_LIT:h>' ) <EOL> zset_b . pop ( '<STR_LIT:i>' ) <EOL> assert_dict_equal ( a , zset_b ) <EOL> a = self . client . zrrange ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> zset_b = params [ '<STR_LIT>' ] . copy ( ) <EOL> zset_b . pop ( '<STR_LIT>' ) <EOL> zset_b . pop ( '<STR_LIT:k>' ) <EOL> assert_dict_equal ( a , zset_b ) <EOL> for k , v in params . items ( ) : <EOL> a = self . client . multi_zget ( k , * v . keys ( ) ) <EOL> assert_dict_equal ( a , v ) <EOL> for k , v in params . items ( ) : <EOL> d = self . client . multi_zdel ( k , * v . keys ( ) ) <EOL> assert_equals ( d , len ( v ) ) <EOL> for k , v in params [ '<STR_LIT>' ] . items ( ) : <EOL> a = self . client . zset ( '<STR_LIT>' , k , v ) <EOL> assert_true ( a ) <EOL> for k , v in params [ '<STR_LIT>' ] . items ( ) : <EOL> a = self . client . zget ( '<STR_LIT>' , k ) <EOL> assert_equals ( a , v ) <EOL> for k , v in params [ '<STR_LIT>' ] . items ( ) : <EOL> a = self . client . zdel ( '<STR_LIT>' , k ) <EOL> assert_true ( a ) <EOL> for k , v in params [ '<STR_LIT>' ] . items ( ) : <EOL> a = self . client . zset ( '<STR_LIT>' , k , v ) <EOL> assert_true ( a ) <EOL> for k , v in params [ '<STR_LIT>' ] . items ( ) : <EOL> a = self . client . zexists ( '<STR_LIT>' , k ) <EOL> assert_true ( a ) <EOL> a = self . client . zexists ( '<STR_LIT>' , k + "<STR_LIT:1>" ) <EOL> assert_false ( a ) <EOL> c = self . client . zsize ( '<STR_LIT>' ) <EOL> assert_equals ( c , len ( params [ '<STR_LIT>' ] ) ) <EOL> c = self . client . zincr ( '<STR_LIT>' , '<STR_LIT:h>' , <NUM_LIT:3> ) <EOL> assert_equals ( c , params [ '<STR_LIT>' ] [ '<STR_LIT:h>' ] + <NUM_LIT:3> ) <EOL> c = self . client . zdecr ( '<STR_LIT>' , '<STR_LIT:h>' , <NUM_LIT:5> ) <EOL> assert_equals ( c , params [ '<STR_LIT>' ] [ '<STR_LIT:h>' ] - <NUM_LIT:5> + <NUM_LIT:3> ) <EOL> d = self . client . zclear ( '<STR_LIT>' ) <EOL> assert_true ( d ) <EOL> def test_zset ( self ) : <EOL> zset_1 = { <EOL> '<STR_LIT:a>' : <NUM_LIT:30> , <EOL> '<STR_LIT:b>' : <NUM_LIT:20> , <EOL> '<STR_LIT:c>' : <NUM_LIT:100> , <EOL> '<STR_LIT:d>' : <NUM_LIT:1> , <EOL> '<STR_LIT:e>' : <NUM_LIT:64> , <EOL> '<STR_LIT:f>' : - <NUM_LIT:3> , <EOL> '<STR_LIT:g>' : <NUM_LIT:0> <EOL> } <EOL> self . client . zclear ( '<STR_LIT>' ) <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> a = self . client . multi_zset ( '<STR_LIT>' , ** zset_1 ) <EOL> assert_equals ( a , len ( zset_1 ) ) <EOL> b = self . client . zcount ( '<STR_LIT>' , <NUM_LIT:20> , <NUM_LIT> ) <EOL> assert_equals ( b , <NUM_LIT:3> ) <EOL> c = self . client . zcount ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> assert_equals ( c , <NUM_LIT:6> ) <EOL> d = self . client . zcount ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert_equals ( d , <NUM_LIT:0> ) <EOL> b = self . client . zsum ( '<STR_LIT>' , <NUM_LIT:20> , <NUM_LIT> ) <EOL> assert_equals ( b , <NUM_LIT> ) <EOL> c = self . client . zsum ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> assert_equals ( c , <NUM_LIT> ) <EOL> d = self . client . zsum ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert_equals ( d , <NUM_LIT:0> ) <EOL> b = self . client . zavg ( '<STR_LIT>' , <NUM_LIT:20> , <NUM_LIT> ) <EOL> assert_equals ( b , <NUM_LIT> ) <EOL> c = self . client . zavg ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> assert_equals ( round ( abs ( c - <NUM_LIT> / <NUM_LIT:6> ) , <NUM_LIT:4> ) , <NUM_LIT:0> ) <EOL> d = self . client . zavg ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert_true ( math . isnan ( float ( '<STR_LIT>' ) ) ) <EOL> b = self . client . zremrangebyrank ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> assert_equals ( b , <NUM_LIT:3> ) <EOL> b = self . client . zremrangebyrank ( '<STR_LIT>' , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> assert_equals ( b , <NUM_LIT:2> ) <EOL> a = self . client . multi_zset ( '<STR_LIT>' , ** zset_1 ) <EOL> b = self . client . zremrangebyscore ( '<STR_LIT>' , <NUM_LIT:20> , <NUM_LIT> ) <EOL> assert_equals ( b , <NUM_LIT:3> ) <EOL> b = self . client . zremrangebyscore ( '<STR_LIT>' , <NUM_LIT:0> , <NUM_LIT:100> ) <EOL> assert_equals ( b , <NUM_LIT:3> ) <EOL> self . client . zclear ( '<STR_LIT>' ) <EOL> self . client . delete ( '<STR_LIT>' ) <EOL> def test_queue ( self ) : <EOL> self . client . qclear ( '<STR_LIT>' ) <EOL> self . client . qclear ( '<STR_LIT>' ) <EOL> queue_1 = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' ] <EOL> queue_2 = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> a = self . client . qpush ( '<STR_LIT>' , * queue_1 ) <EOL> assert_equals ( a , len ( queue_1 ) ) <EOL> a = self . client . qpush ( '<STR_LIT>' , * queue_2 ) <EOL> assert_equals ( a , len ( queue_2 ) ) <EOL> a = self . client . qsize ( '<STR_LIT>' ) <EOL> assert_equals ( a , len ( queue_1 ) ) <EOL> a = self . client . qlist ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( a , [ '<STR_LIT>' ] ) <EOL> a = self . client . qlist ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( a , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> a = self . client . qlist ( '<STR_LIT:z>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( a , [ ] ) <EOL> a = self . client . qrlist ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( a , [ '<STR_LIT>' ] ) <EOL> a = self . client . qrlist ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( a , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> a = self . client . qrlist ( '<STR_LIT:z>' , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_equals ( a , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> a = self . client . qfront ( '<STR_LIT>' ) <EOL> assert_equals ( a , '<STR_LIT:a>' ) <EOL> a = self . client . qback ( '<STR_LIT>' ) <EOL> assert_equals ( a , '<STR_LIT:g>' ) <EOL> a = self . client . qget ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> assert_equals ( a , '<STR_LIT:c>' ) <EOL> a = self . client . qget ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> assert_equals ( a , '<STR_LIT:a>' ) <EOL> a = self . client . qget ( '<STR_LIT>' , - <NUM_LIT:1> ) <EOL> assert_equals ( a , '<STR_LIT:g>' ) <EOL> a = self . client . qset ( '<STR_LIT>' , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> a = self . client . qget ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> assert_equals ( a , '<STR_LIT>' ) <EOL> a = self . client . qset ( '<STR_LIT>' , <NUM_LIT:0> , '<STR_LIT:a>' ) <EOL> a = self . client . qrange ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> a = self . client . qrange ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:10> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' ] ) <EOL> a = self . client . qrange ( '<STR_LIT>' , - <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:g>' ] ) <EOL> a = self . client . qslice ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:c>' ] ) <EOL> a = self . client . qslice ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> a = self . client . qslice ( '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:10> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' ] ) <EOL> a = self . client . qslice ( '<STR_LIT>' , - <NUM_LIT:3> , <NUM_LIT:5> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:e>' , '<STR_LIT:f>' ] ) <EOL> a = self . client . qpush_back ( '<STR_LIT>' , '<STR_LIT:h>' ) <EOL> assert_equals ( a , <NUM_LIT:8> ) <EOL> a = self . client . qpop_back ( '<STR_LIT>' ) <EOL> assert_list_equal ( a , [ '<STR_LIT:h>' ] ) <EOL> a = self . client . qpush_back ( '<STR_LIT>' , '<STR_LIT:h>' , '<STR_LIT:i>' , '<STR_LIT>' , '<STR_LIT:k>' ) <EOL> assert_equals ( a , <NUM_LIT:11> ) <EOL> a = self . client . qpop_back ( '<STR_LIT>' , <NUM_LIT:4> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:k>' , '<STR_LIT>' , '<STR_LIT:i>' , '<STR_LIT:h>' ] ) <EOL> a = self . client . qpush ( '<STR_LIT>' , '<STR_LIT:h>' ) <EOL> assert_equals ( a , <NUM_LIT:8> ) <EOL> a = self . client . qpop_back ( '<STR_LIT>' ) <EOL> assert_list_equal ( a , [ '<STR_LIT:h>' ] ) <EOL> a = self . client . qpush ( '<STR_LIT>' , '<STR_LIT:h>' , '<STR_LIT:i>' , '<STR_LIT>' , '<STR_LIT:k>' ) <EOL> assert_equals ( a , <NUM_LIT:11> ) <EOL> a = self . client . qpop_back ( '<STR_LIT>' , <NUM_LIT:4> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:k>' , '<STR_LIT>' , '<STR_LIT:i>' , '<STR_LIT:h>' ] ) <EOL> a = self . client . qpush_front ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> assert_equals ( a , <NUM_LIT:8> ) <EOL> a = self . client . qpop_front ( '<STR_LIT>' ) <EOL> assert_list_equal ( a , [ '<STR_LIT:0>' ] ) <EOL> a = self . client . qpush_front ( '<STR_LIT>' , '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' ) <EOL> assert_equals ( a , <NUM_LIT:11> ) <EOL> a = self . client . qpop_front ( '<STR_LIT>' , <NUM_LIT:4> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:3>' , '<STR_LIT:2>' , '<STR_LIT:1>' , '<STR_LIT:0>' ] ) <EOL> a = self . client . qpush_front ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> assert_equals ( a , <NUM_LIT:8> ) <EOL> a = self . client . qpop ( '<STR_LIT>' ) <EOL> assert_list_equal ( a , [ '<STR_LIT:0>' ] ) <EOL> a = self . client . qpush_front ( '<STR_LIT>' , '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' ) <EOL> assert_equals ( a , <NUM_LIT:11> ) <EOL> a = self . client . qpop ( '<STR_LIT>' , <NUM_LIT:4> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:3>' , '<STR_LIT:2>' , '<STR_LIT:1>' , '<STR_LIT:0>' ] ) <EOL> a = self . client . qrem_front ( '<STR_LIT>' , <NUM_LIT:3> ) <EOL> assert_equals ( a , <NUM_LIT:3> ) <EOL> a = self . client . qpop ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' ] ) <EOL> a = self . client . qpush ( '<STR_LIT>' , * queue_1 ) <EOL> assert_equals ( a , len ( queue_1 ) ) <EOL> a = self . client . qrem_back ( '<STR_LIT>' , <NUM_LIT:3> ) <EOL> assert_equals ( a , <NUM_LIT:3> ) <EOL> a = self . client . qpop ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> assert_list_equal ( a , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] ) <EOL> a = self . client . qpush ( '<STR_LIT>' , * queue_1 ) <EOL> assert_equals ( a , len ( queue_1 ) ) <EOL> a = self . client . qpop ( '<STR_LIT>' , len ( queue_1 ) ) <EOL> assert_list_equal ( a , queue_1 ) <EOL> a = self . client . qclear ( '<STR_LIT>' ) <EOL> assert_equals ( a , <NUM_LIT:6> ) <EOL> b = self . client . qclear ( '<STR_LIT>' ) <EOL> assert_equals ( b , <NUM_LIT:0> ) </s>
