
    Vh                     h    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZmZ d Zedk(  r e        y	y	)
    )absolute_importdivisionprint_functionaC  
module: redis_data
short_description: Set key value pairs in Redis
version_added: 3.7.0
description:
  - Set key value pairs in Redis database.
author: "Andreas Botzner (@paginabianca)"
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  key:
    description:
      - Database key.
    required: true
    type: str
  value:
    description:
      - Value that key should be set to.
    required: false
    type: str
  expiration:
    description:
      - Expiration time in milliseconds. Setting this flag will always result in a change in the database.
    required: false
    type: int
  non_existing:
    description:
      - Only set key if it does not already exist.
    required: false
    type: bool
  existing:
    description:
      - Only set key if it already exists.
    required: false
    type: bool
  keep_ttl:
    description:
      - Retain the time to live associated with the key.
    required: false
    type: bool
  state:
    description:
      - State of the key.
    default: present
    type: str
    choices:
      - present
      - absent

extends_documentation_fragment:
  - community.general.redis.documentation
  - community.general.attributes

seealso:
  - module: community.general.redis_data_incr
  - module: community.general.redis_data_info
  - module: community.general.redis
aF  
- name: Set key foo=bar on localhost with no username
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    value: bar
    state: present

- name: Set key foo=bar if non existing with expiration of 30s
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    value: bar
    non_existing: true
    expiration: 30000
    state: present

- name: Set key foo=bar if existing and keep current TTL
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    value: bar
    existing: true
    keep_ttl: true

- name: Set key foo=bar on redishost with custom ca-cert file
  community.general.redis_data:
    login_host: redishost
    login_password: supersecret
    login_user: someuser
    validate_certs: true
    ssl_ca_certs: /path/to/ca/certs
    key: foo
    value: bar

- name: Delete key foo on localhost with no username
  community.general.redis_data:
    login_host: localhost
    login_password: supersecret
    key: foo
    state: absent
a  
old_value:
  description: Value of key before setting.
  returned: on_success if O(state=present) and key exists in database.
  type: str
  sample: 'old_value_of_key'
value:
  description: Value key was set to.
  returned: on success if O(state=present).
  type: str
  sample: 'new_value_of_key'
msg:
  description: A short message.
  returned: always
  type: str
  sample: 'Set key: foo to bar'
)AnsibleModule)fail_importsredis_auth_argument_specRedisAnsiblec                     t               } t        t        ddd      t        dd      t        dd      t        dd      t        dd      t        dd      t        dddd	g
            }|j                  |        t        |ddgddgddgg      }t	        |       t        |      }|j                  d   }|j                  d   }|j                  d   }|j                  d   }|j                  d   }|j                  d   }	|j                  d   }
||||||	d}ddi}d }	 |j                  j                  |      }|
d	k(  r|j                  rS|)dj                  |      }||d<    |j                  d#i | n(dj                  |      }||d<    |j                  d#i | 	 |j                  j                  |      }|dk(  r)dj                  |      }||d<    |j                  d#i | n-dj                  |      }||d<   d|d<    |j                  d#i | d }	 |j                  j                  |      }||d<   ||k(  r3|	dur/|-dj                  |      }||d<   ||d<    |j                  d#i | |j                  r+dj                  |      |d<   ||d<    |j                  d#i | 	  |j                  j                   d#i |}|<|rd j                  |      }nd!j                  |      }||d<    |j                  d#i | dj                  |      }||d<   d|d<   ||d<    |j                  d#i | y # t        $ r=}dj                  |t        |            }||d<    |j                  d#i | Y d }~<d }~ww xY w# t        $ r=}dj                  |t        |            }||d<    |j                  d#i | Y d }~d }~ww xY w# t        $ r=}dj                  |t        |            }||d<    |j                  d#i | Y d }~d }~ww xY w# t        $ r<}d"j                  |t        |            }||d<    |j                  d#i | Y d }~y d }~ww xY w)$NstrTF)typerequiredno_log)r   r   intboolpresentabsent)r   defaultchoices)keyvalue
expirationnon_existingexistingkeep_ttlstate)r   r   )r   r   r   r   r   )argument_specsupports_check_moderequired_ifmutually_exclusiver   r   r   )namer   pxnxxxkeepttlchangedz3Failed to get value of key: {0} with exception: {1}msgzKey: {0} not presentzDeleted key: {0}r   z-Failed to delete key: {0} with exception: {1}	old_valuez!Key {0} already has desired valuezSet key: {0}z,Could not set key: {0}. Key already present.z(Could not set key: {0}. Key not present.z*Failed to set key: {0} with exception: {2} )r   dictupdater   r   r	   params
connectionget	Exceptionformatr   	fail_json
check_mode	exit_jsondeleteset)redis_auth_argsmodule_argsmoduleredisr   r   r!   r"   r#   r$   r   set_argsresultr'   er&   rets                    p/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/redis_data.pymainr>      s   .0Oed59.UU3v66E26E2y%x02	K '! 56+Z8'68	:F  E
--
CMM'"E	|	$B	~	&B	z	"BmmJ'GMM'"Ee2w8H FI#$$((-	  ,33C8 #u   *6*(//4 #u   *6*	'""))#.Cax,33C8 #u   *6*(//4 #u$(y!   *6* I#$$((-	 $F;EgU2rz188=uw"6"&--c2uw"6"#"e"".X.;DKK AGGLF5MF&v&##C(u yw"6"E  #CJJQu"6""	#6  	'AHHSVCF5MF&v&&		'  #CJJQu"6""	#>  #:AA#s1vNu"6"#sb   $L: $A6N O -BP :	N 2M;;N 	O	2OO		P2PP	Q2QQ__main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   @ansible_collections.community.general.plugins.module_utils.redisr   r   r	   r>   __name__r(       r=   <module>rI      sT    A @<|,\
$ 5: :m#` zF rH   