d;%Q d dl mZ d dlZd dlmZmZmZ d dlmZ d dl mZmZ d dl mZ G d de Z G d d e Z G d de ZdS ) )absolute_importN)OptionalTupleDict)gettext)ExternalProgramFailedrun_command) WposErrorc " e Zd ZdZ fdZ xZS )DeadRedisPurgeAttemptzW Happens when somebody tries to purge redis instance which is not runnning c f t t d d S )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.pyr zDeadRedisPurgeAttempt.__init__ sE Y"Z "Z [ [ [ [ [ )__name__ __module____qualname____doc__r __classcell__r s @r r r sK [ [ [ [ [ [ [ [ [r r c , e Zd ZdZdedef fdZ xZS )PurgeFailedErrorzN Happens when redis is not able to purge cached data for some reason. std_outstd_errc z t t d dd|pd|pdd d S )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)r detailscontextr )r r r r s r r zPurgeFailedError.__init__# sg ] ^ ^4 #!,W!,W r )r r r r strr r r s @r r r sU c r r c e Zd Z ddededdfdZd Zdedeeeef fd Zde fd Z defdZdefdZ dee fd ZdS )RedisLibUser/opt/alt/redis/bin/redis-clisocket_pathredis_cli_pathreturnNc " || _ || _ d S )N)r- r. )r r- r. s r r zRedisLibUser.__init__4 s &,r c L | j d| j g| d z S )Nz-s )r. r- split)r redis_commands r get_redis_shell_commandz$RedisLibUser.get_redis_shell_command9 s3 $$ % %r r$ c " | | } t |d \ }}}n_# t j t f$ rF}t t d d | t | d d }~ww xY w|||fS )NT)return_full_outputz6Error during %(command)s command execution: %(error)sr2 )r$ error)r r( ) r5 r subprocessCalledProcessErrorr r r joinr) )r r$ r4 returncoder r r8 s r run_redis_commandzRedisLibUser.run_redis_command@ s 44W== +6$, , ,(J -/DE STT$'HH]$;$;c%jjQQ 7G++s - B ABB c | st d}| | \ }}}|dk sd| vrt || d| iS )z4 Clean entire redis cache for user. zflushall asyncr okused_memory)is_redis_aliver r= lowerr get_redis_used_memory)r purge_commandr<