d;%QddlmZddlZddlmZmZmZddlmZ ddl m Z m Z ddl mZGddeZGd d eZGd d eZdS) )absolute_importN)OptionalTupleDict)gettext)ExternalProgramFailed run_command) WposErrorc"eZdZdZfdZxZS)DeadRedisPurgeAttemptzW Happens when somebody tries to purge redis instance which is not runnning cfttddS)NzUnable to purge cache because cache database is not running. Enable at least one optimization feature to start cache database instance.)messagesuper__init___)self __class__s py/clwpos/user/redis_lib.pyrzDeadRedisPurgeAttempt.__init__sE  Y"Z"Z [ [ [ [ [)__name__ __module__ __qualname____doc__r __classcell__rs@rr r sK [[[[[[[[[rr c,eZdZdZdedeffd ZxZS)PurgeFailedErrorzN Happens when redis is not able to purge cached data for some reason. std_outstd_errczttddd|pd|pdddS)NzUnable to purge cache. Database backend returned error of command "%(command)s" execution. Try again a bit later or contact your system administrator for help.z6stdout: %(stdout)s stderr: %(stderr)s purgeempty)commandstdoutstderr)rdetailscontextr)rrr rs rrzPurgeFailedError.__init__#sg ]^^4#!,W!,W      r)rrrrstrrrrs@rrrsU  c          rrceZdZ ddededdfdZdZdedeeeeffd Zde fd Z de fd Z de fd Z deefd ZdS) RedisLibUser/opt/alt/redis/bin/redis-cli socket_pathredis_cli_pathreturnNc"||_||_dS)N)r-r.)rr-r.s rrzRedisLibUser.__init__4s&,rcL|jd|jg|dzS)Nz-s )r.r-split)r redis_commands rget_redis_shell_commandz$RedisLibUser.get_redis_shell_command9s3          $ $ % %rr$c"||} t|d\}}}n_#tjtf$rF}t t dd|t|dd}~wwxYw|||fS)NT)return_full_outputz6Error during %(command)s command execution: %(error)sr2)r$error)rr() r5r subprocessCalledProcessErrorrr rjoinr))rr$r4 returncoderr r8s rrun_redis_commandzRedisLibUser.run_redis_command@s44W==  +6$,,, (J-/DE   STT$'HH]$;$;c%jjQQ   7G++s-B ABB c|std}||\}}}|dksd|vrt ||d|iS)z4 Clean entire redis cache for user. zflushall asyncrok used_memory)is_redis_aliver r=lowerrget_redis_used_memory)r purge_commandr<rr s r purge_rediszRedisLibUser.purge_redisMs""$$ *')) )( '+'='=m'L'L$ GW ??d'--//99"7G44 4 45577  rcl|d\}}}|dkod|vS)z1 Check if user's redis is alive. pingrpong)r=rBrr<rrs rrAzRedisLibUser.is_redis_alive^s:"&!7!7!?!? GQQ<6W]]__#<r`s#'&&&&&((((((((((========////// [ [ [ [ [I [ [ [y(ONONONONON6ONONONONONr