#NEWLINE# def get_redis_backend( ) : #NEWLINE# #INDENT# 'Connect to redis from a string like CACHE_BACKEND.' #NEWLINE# ( server , params ) = parse_backend_uri ( settings . REDIS_BACKEND ) #NEWLINE# db = params . pop ( 'db' , 0 ) #NEWLINE# try : #NEWLINE# #INDENT# db = int ( db ) #NEWLINE# #UNINDENT# except ( ValueError , TypeError ) : #NEWLINE# #INDENT# db = 0 #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# socket_timeout = float ( params . pop ( 'socket_timeout' ) ) #NEWLINE# #UNINDENT# except ( KeyError , ValueError ) : #NEWLINE# #INDENT# socket_timeout = None #NEWLINE# #UNINDENT# password = params . pop ( 'password' , None ) #NEWLINE# if ( ':' in server ) : #NEWLINE# #INDENT# ( host , port ) = server . split ( ':' ) #NEWLINE# try : #NEWLINE# #INDENT# port = int ( port ) #NEWLINE# #UNINDENT# except ( ValueError , TypeError ) : #NEWLINE# #INDENT# port = 6379 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# host = 'localhost' #NEWLINE# port = 6379 #NEWLINE# #UNINDENT# return redislib . Redis ( host = host , port = port , db = db , password = password , socket_timeout = socket_timeout )