def flush_all_host_configs_into_redis(): applied_hosts = [] for group in hosts.monitored_groups: applied_hosts.extend(group.hosts) applied_hosts = set(applied_hosts) redishelper = RedisHelper() for host in applied_hosts: host_config = host_config_serialize(host) key = 'HostConfig::%s' % host redishelper.set(key,pickle.dump(host_config)) return True
def flush_all_host_configs_into_redis(): applied_hosts = [] redis = RedisHelper() for group in hosts.monitored_groups: applied_hosts.extend(group.hosts) applied_hosts = set(applied_hosts) for host_ip in applied_hosts: host_config = host_config_serializer(host_ip) key = 'HostConfig::%s' % host_ip redis.set(key, pickle.dumps(host_config)) return True
def flush_all_host_configs_into_redis(): #把所有配置刷到redis applied_hosts = [] redis = RedisHelper() for group in monitored_groups: applied_hosts.extend(group.hosts) applied_hosts = set(applied_hosts) for host_ip in applied_hosts: host_config = host_config_serializer(host_ip) # 序列化字典后存入redis key = 'HostConfig::%s' % host_ip redis.set(key, pickle.dumps(host_config))
def flush_all_host_configs_into_redis(): applied_hosts = [] redis = RedisHelper() for group in hosts.monitored_groups: applied_hosts.extend(group.hosts) applied_hosts = set(applied_hosts) for host_ip in applied_hosts: host_config = host_config_serialize(host_ip) #redis中只存字符串和数字,并不认识python的字典,所以需要序列化(序列化后就变成字符串了),因为这个程序都是用python写的,而且pickle可以序列化的数据类型比较多 key = 'HostConfig::%s' %host_ip #给这个key加一个标识,这样以后添加其他信息时方便区分识别 redis.set(key,pickle.dumps(host_config)) return True
def flush_all_host_configs_into_redis(): applied_hosts = [] redis = RedisHelper() for group in hosts.monitored_groups: applied_hosts.extend(group.hosts) applied_hosts = set(applied_hosts) for host_ip in applied_hosts: host_config = host_config_serializer(host_ip) key = 'HostConfig::%s' % host_ip redis.set(key, pickle.dumps(host_config)) print host_config return True
#! /usr/bin/env python # coding:utf-8 """ 在redis设置一个key,然后去获取他得值 """ from redishelper import RedisHelper r = RedisHelper() # 设置key r.set('name','wweeee2222') # 获取key print(r.get('name'))