sys.path.append(os.environ['QUANT_HOME'] + '/lib') #from Redis import RedisInfo #r = RedisInfo() from redis import Redis, exceptions, RedisError from redis.sentinel import (Sentinel, SentinelConnectionPool, ConnectionError, MasterNotFoundError, SlaveNotFoundError) # Redis 접속 기본 설정값 listSentinel = [('172.31.5.41', 26379)] strServiceName = 'mymaster' strRedisPass = '' nDB = 0 sentinel = Sentinel(listSentinel) master = sentinel.master_for(strServiceName, password=strRedisPass, db=nDB) slave = sentinel.slave_for(strServiceName, password=strRedisPass, db=nDB) rds = master rds_pub = rds.pubsub() rds_pub.subscribe('0_Text_0') """ print sys.argv[1] """ while True: try: for x in rds_pub.listen(): print "Text :", x['data'] except Exception, e: print "Exception :", e
@func:通过企业详情链接获取企业信息 """ import datetime import re,scrapy import time import zlib import requests from en_plugin.scrapy.items import InvoiceTitleItem from redis.sentinel import Sentinel from QCC.Cookie.cookie import Cookie from QCC.items.MDetailItem import MDetailtItem from QCC.settings import REDIS_ENAME_DB as redis_ename_db from bwjf_scrapy_redis.utils import bytes_to_str from bwjf_scrapy.spider.BwjfRedisSpider import BwjfRedisSpider sentinel = Sentinel([], socket_timeout=5) r = sentinel.master_for('mymaster', socket_timeout=5, db=0) headers = { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Host": "www.qichacha.com", "Referer": "https://www.qichacha.com/", "Upgrade-Insecure-Requests": "1", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36", } cookie = Cookie()
from ...models import ( Item, AddItemRequest, AddItemResponse, GetItemResponse, ListItemsResponse, ) from fastapi import APIRouter, HTTPException from redis.sentinel import Sentinel router = APIRouter() logger = structlog.getLogger("redis-items") sentinel = Sentinel([('redis-0.redis', 26379)], socket_timeout=0.1) @router.put( "/{key}", summary="Create redis item", response_model=AddItemResponse, ) def add(key: str, req: AddItemRequest): logger.info("Adding redis item", key=key, value=req.value) master = sentinel.master_for( "redis") # slaves are read-only; use master for writes master.set(key, req.value) return AddItemResponse(key=key, value=req.value)
from redis.sentinel import Sentinel sentinel = Sentinel([("127.0.0.1", 26379), ("127.0.0.1", 26380), ("127.0.0.1", 26381)], socket_timeout=0.1) print(sentinel.discover_master("mymaster")) print(sentinel.discover_slaves("mymaster"))
BLOG_URL = 'https://example.com' # Redis sentinel REDIS_SENTINEL_SERVICE_HOST = None REDIS_SENTINEL_SERVICE_PORT = 26379 SHOW_AUTHOR = False try: with open(HERE / 'config.yaml') as f: partials = AttrDict(yaml.safe_load(f)).partials USE_YAML = True except FileNotFoundError: USE_YAML = False partials = {} try: from local_settings import * # noqa except ImportError: pass redis_sentinel_host = os.getenv( 'REDIS_SENTINEL_SVC_HOST') or REDIS_SENTINEL_SERVICE_HOST # noqa if redis_sentinel_host: redis_sentinel_port = os.getenv('REDIS_SENTINEL_SVC_PORT', REDIS_SENTINEL_SERVICE_PORT) from redis.sentinel import Sentinel sentinel = Sentinel([(redis_sentinel_host, redis_sentinel_port)], socket_timeout=0.1) redis_host, redis_port = sentinel.discover_master('mymaster') REDIS_URL = f'redis://{redis_host}:{redis_port}'
def get_connect(self): # 获取数据库连接 try: if not self._url: if not self._ip_ports: raise Exception("未设置 redis 连接信息") ip_ports = (self._ip_ports if isinstance(self._ip_ports, list) else self._ip_ports.split(",")) if len(ip_ports) > 1: startup_nodes = [] for ip_port in ip_ports: ip, port = ip_port.split(":") startup_nodes.append({"host": ip, "port": port}) if self._service_name: # log.debug("使用redis哨兵模式") hosts = [(node["host"], node["port"]) for node in startup_nodes] sentinel = Sentinel(hosts, socket_timeout=3, **self._kwargs) self._redis = sentinel.master_for( self._service_name, password=self._user_pass, db=self._db, redis_class=redis.StrictRedis, decode_responses=self._decode_responses, max_connections=self._max_connections, **self._kwargs, ) else: # log.debug("使用redis集群模式") self._redis = RedisCluster( startup_nodes=startup_nodes, decode_responses=self._decode_responses, password=self._user_pass, max_connections=self._max_connections, **self._kwargs, ) self._is_redis_cluster = True else: ip, port = ip_ports[0].split(":") self._redis = redis.StrictRedis( host=ip, port=port, db=self._db, password=self._user_pass, decode_responses=self._decode_responses, max_connections=self._max_connections, **self._kwargs, ) self._is_redis_cluster = False else: self._redis = redis.StrictRedis.from_url( self._url, decode_responses=self._decode_responses) self._is_redis_cluster = False except Exception as e: raise # 不要写成self._redis.ping() 否则循环调用了 return self.__redis.ping()
def get_sentinel_client(self, instance=None): sentinels = self.__get_admin_sentinel_connection(instance) sentinel = Sentinel( sentinels, socket_timeout=self.connection_timeout_in_seconds, socket_connect_timeout=self.connection_socket_timeout_in_seconds ) return sentinel
""" 哨兵使用 """ from redis.sentinel import Sentinel sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1) master = sentinel.master_for("mymaster", socket_timeout=0.1) slave = sentinel.slave_for("mymaster", socket_timeout=0.1) print(master, slave) master.set("test_master", "我是你爸爸") print(slave.get("test_master"))
#!/usr/bin/env python3 import sys from redis.sentinel import Sentinel, MasterNotFoundError from redis.exceptions import ConnectionError from time import sleep print('Connecting to Sentinel...') sentinel = Sentinel([('localhost', '16379')], socket_timeout=10) print('Connecting to master...') master = sentinel.master_for('redis-cluster', socket_timeout=10) while True: try: master.incr('counter') except (MasterNotFoundError, ConnectionError): print('Connection error. Connecting to master...') master = sentinel.master_for('redis-cluster', socket_timeout=10) print('Incremented by 1.') sys.stdout.flush() sleep(1)
def default_redis_sentinel_factory(config): ''' Default redis client factory for sentinel mode. :param config: A dict with the Redis configuration parameters :type config: dict :return: A Sentinel object using the provided config values :rtype: Sentinel ''' sentinels = config.get('redisSentinels') if (sentinels is None): raise SentinelConfigurationException( 'redisSentinels must be specified.') if (not isinstance(sentinels, list)): raise SentinelConfigurationException( 'Sentinels must be an array of elements in the form of' ' [(ip, port)].') if (len(sentinels) == 0): raise SentinelConfigurationException( 'It must be at least one sentinel.') if not all(isinstance(s, tuple) for s in sentinels): raise SentinelConfigurationException( 'Sentinels must respect the tuple structure' '[(ip, port)].') master_service = config.get('redisMasterService') if (master_service is None): raise SentinelConfigurationException( 'redisMasterService must be specified.') db = config.get('redisDb', 0) password = config.get('redisPassword', None) socket_timeout = config.get('redisSocketTimeout', None) socket_connect_timeout = config.get('redisSocketConnectTimeout', None) socket_keepalive = config.get('redisSocketKeepalive', None) socket_keepalive_options = config.get('redisSocketKeepaliveOptions', None) connection_pool = config.get('redisConnectionPool', None) unix_socket_path = config.get('redisUnixSocketPath', None) encoding = config.get('redisEncoding', 'utf-8') encoding_errors = config.get('redisEncodingErrors', 'strict') charset = config.get('redisCharset', None) errors = config.get('redisErrors', None) decode_responses = config.get('redisDecodeResponses', False) retry_on_timeout = config.get('redisRetryOnTimeout', False) ssl = config.get('redisSsl', False) ssl_keyfile = config.get('redisSslKeyfile', None) ssl_certfile = config.get('redisSslCertfile', None) ssl_cert_reqs = config.get('redisSslCertReqs', None) ssl_ca_certs = config.get('redisSslCaCerts', None) max_connections = config.get('redisMaxConnections', None) prefix = config.get('redisPrefix') sentinel = Sentinel( sentinels, 0, { 'db': db, 'password': password, 'socket_timeout': socket_timeout, 'socket_connect_timeout': socket_connect_timeout, 'socket_keepalive': socket_keepalive, 'socket_keepalive_options': socket_keepalive_options, 'connection_pool': connection_pool, 'unix_socket_path': unix_socket_path, 'encoding': encoding, 'encoding_errors': encoding_errors, 'charset': charset, 'errors': errors, 'decode_responses': decode_responses, 'retry_on_timeout': retry_on_timeout, 'ssl': ssl, 'ssl_keyfile': ssl_keyfile, 'ssl_certfile': ssl_certfile, 'ssl_cert_reqs': ssl_cert_reqs, 'ssl_ca_certs': ssl_ca_certs, 'max_connections': max_connections }) redis = sentinel.master_for(master_service) return PrefixDecorator(redis, prefix=prefix)
#!/usr/bin/env python # -*- coding: utf-8 -*- # 获取主服务器地址 from redis.sentinel import Sentinel sentinel = Sentinel([('192.168.168.136', 16379), ('192.168.168.119', 16379), ('192.168.168.110', 16379)], socket_timeout=0.1, password='******') print sentinel.discover_master('mymaster6379') # 输出:('192.168.168.136', 6379) # 获取从服务器地址 print sentinel.discover_slaves('mymaster6379') # 输出:[('192.168.168.119', 6379), ('192.168.168.100', 6379)] # 获取从服务器进行读取(默认是round-roubin) slave = sentinel.slave_for('mymaster6379', socket_timeout=0.1) print slave.keys() print slave.hkeys('zabbix') print slave.hget('zabbix', 'getTestMonitor_192.168.168.147') # print slave.get('getMonitor_192.168.168.147') # # 获取主服务器进行写入 master = sentinel.master_for('mymaster6379', socket_timeout=0.1) print master.info() # master.set('getMonitor_192.168.172.7', rs)
#!/usr/bin/python from redis.sentinel import Sentinel sentinel = Sentinel([('localhost', 16001), ("localhost", 16002), ("localhost", 16003)], socket_timeout=0.1) master = sentinel.discover_master('redis-cluster') slaves = sentinel.discover_slaves('redis-cluster') print "" print "Master(" + str(master) + ")" print "" print "Slaves(" + str(len(slaves)) + ") Nodes(" + str(slaves) + ")" print ""
# https://www.cnblogs.com/linkenpark/p/7841608.html import redis from redis.sentinel import Sentinel sentinel = Sentinel([ ('localhost', 26376), ('localhost', 26377), ('localhost', 26378), ('localhost', 26379), ], socket_timeout=0.5) master = sentinel.discover_master('mymaster') print(master) slave = sentinel.discover_master('mymaster') print(master)
import redis try: from django.utils.encoding import force_unicode except ImportError: # Python 3.* from django.utils.encoding import force_text as force_unicode from django.contrib.sessions.backends.base import SessionBase, CreateError from redis_sessions import settings # Avoid new redis connection on each request if settings.SESSION_REDIS_SENTINEL_LIST is not None: from redis.sentinel import Sentinel redis_server = Sentinel(settings.SESSION_REDIS_SENTINEL_LIST, socket_timeout=0.1) \ .master_for(settings.SESSION_REDIS_SENTINEL_MASTER_ALIAS, socket_timeout=0.1) elif settings.SESSION_REDIS_URL is not None: redis_server = redis.StrictRedis.from_url(settings.SESSION_REDIS_URL) elif settings.SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH is None: redis_server = redis.StrictRedis( host=settings.SESSION_REDIS_HOST, port=settings.SESSION_REDIS_PORT, db=settings.SESSION_REDIS_DB, password=settings.SESSION_REDIS_PASSWORD ) else: redis_server = redis.StrictRedis(
class SocketHandler(SockJSConnection): client_sock = {} sent = Sentinel([('127.0.0.1', 17777)], socket_timeout=0.1) data_base = sent.master_for('mymaster', socket_timeout=0.1) def on_open(self, request): print('socket open') def on_close(self): print('socket close') def on_message(self, message): message_array = message.split(':') if message_array[0] == 'name': SocketHandler.client_sock[message_array[1]] = self messages = Messages.objects.filter( id_receiver__login=message_array[1]) for mes in messages: user = Credential.objects.filter(id=mes.id_sender_id).first() output = user.login + ':' + mes.message self.send(output) broadcast_messages = SocketHandler.data_base.lrange( 'broadcast', 0, -1) for br_mes in broadcast_messages: output = 'broadcast:' + str(br_mes) self.send(output) elif message_array[0] == 'list_active': print('list_active') output = 'list_active:' for key in SocketHandler.client_sock.keys(): output += key + '\n' self.send(output) elif message_array[0] == 'list_all': print('list_all') output = 'list_all:' users = Credential.objects.all() for user in users: output += user.login + '\n' self.send(output) elif message_array[0] == 'broadcast': SocketHandler.data_base.lpush('broadcast', message_array[1]) SocketHandler.data_base.expire('broadcast', 1000) output_message = message_array[0] + ':' + message_array[1] for client in SocketHandler.client_sock.values(): client.send(output_message) else: receiver_name = message_array[0] sender_name = None for name, sock in SocketHandler.client_sock.items(): if sock == self: sender_name = name break output_message = sender_name + ':' + message_array[1] if receiver_name in SocketHandler.client_sock.keys(): SocketHandler.client_sock[receiver_name].send(output_message) else: credential_sender = Credential.objects.filter( login=sender_name).first() credential_receiver = Credential.objects.filter( login=receiver_name).first() mes = Messages(id_sender=credential_sender, id_receiver=credential_receiver, message=message_array[1]) mes.save()
# -*- coding: utf-8 -*- """ __author__ = 'do' __mtime__ = '2017/12/4' __content__ = '' """ import redis from redis.sentinel import Sentinel import time host = [["127.0.0.1",7379],["127.0.0.1",7380]] password = '******' sentinel = Sentinel(host) print sentinel.discover_master('mymaster') r = sentinel.master_for('mymaster',password=password) all_userid = ['895185', '2641093', '2406725', '1076206', '1183233', '5553314', '1428172', '624953', '5552244', '6438616', '1387090', '3572136', '258256', '6430542', '6421055', '6366053', '5535272', '850606', '6430549', '6926381', '6376166', '6455005', '2335559', '4189558', '3935553', '6077156', '2579033', '5068024', '5535271', '6430981', '5551361', '980913', '1974380', '6395268', '2951014', '6418222', '2003793', '1424122', '5516318', '2620565', '6429594', '6504448', '6404855', '6428182', '6429691', '621111', '2380951', '5485517', '5911364', '324060', '3141369', '1162071', '3049830', '5530157', '1012747', '917308', '1147315', '5401999', '1915578', '3953960', '3124952', '5542646', '2978306', '820516', '6457789', '6418610', '3587168', '3938500', '3002972', '1300835', '3938977', '5551731', '3229579', '2418965', '6382809', '1698093', '1540669', '5291775', '6422161', '2649318', '6429614', '2933300', '5765437', '5534077', '1236260', '6446771', '5813665', '6419073', '1379730', '3188488', '2224931', '176249', '5553332', '6447431', '5552409', '2310930', '3103576', '4676116', '1589787', '342037', '5449773', '5553048', '2696280', '2027098', '5535502', '2029868', '5535882', '6449138', '6454250', '2812913', '1082342', '6391343', '6399846', '6431144', '3091437', '3770112', '4667554', '6423699', '6060757', '6433454', '6399863', '536037', '1067233', '5547121', '2688602', '3108270', '6430674', '6453416', '3329522', '2752890', '6423747', '6399901', '1654132', '5546118', '5530570', '711873', '6454008', '2952831', '3015163', '5542494', '2026433', '6461260', '6443962', '5135568', '815735', '6424717', '1642207', '3615170', '6433183', '832553', '5017830', '6407841', '6375764', '913345', '2430921', '602013', '1182892', '2752875', '771877', '6454323', '340440', '1983948', '3179653', '439417', '1235766', '1219898', '5522535', '6447557', '1404481', '6429773', '5426151', '3050026', '6414325', '328798', '355657', '6432041', '819710', '6446686', '820754', '5484235', '5001021', '586996', '4417490', '6447838', '2101155', '2141819', '617221', '3080555', '4010538', '812182', '6446593', '6430620', '4560720', '792549', '6448143', '5539765', '1283196', '2014637', '6384067', '2532273', '2765355', '6449022', '2913480', '720639', '5303327', '5544123', '2623899', '3957003', '1589769', '1348343', '1060035', '5552420', '6011888', '2029880', '351853', '6447887', '780128', '6404749', '6438582', '6452401', '1377243', '6382528', '6422285', '337837', '3014449', '2599782', '5403630', '629784', '6446740', '6429860', '6438571', '5545551', '720024', '3409381', '2797366', '2906595', '399575', '914836', '628064', '3081020', '749666', '5545777', '1197874', '5717328', '1453163', '900723', '1348506', '530622', '5227932', '6452696', '5458860', '381851', '410596', '355856', '2345139', '2988803', '6400818', '1104064', '1059224', '3113749', '2954193', '6441322', '2837277', '5552529', '2744458', '4803153', '826517', '6439853', '6347669', '2154089', '340062', '618654', '1541641', '6140593', '2193738', '621087', '2696313', '6454125', '290133', '5543911', '6255539', '362522', '6274965', '355947', '753955', '1088410', '6401270', '5901016', '5535866', '4806168', '554181', '6045584', '6419667', '6437851', '6462344', '6004394', '698733', '5544651', '3818503', '2530166', '1363247', '1301968', '3695470', '2096001', '3354573', '2198229', '3806085', '1377390', '454470', '451058', '3092249', '2649437', '4840524', '4688925', '1509368', '6396531', '226872', '836670', '6414272', '2994535', '1464885', '2247017', '3941588', '3233578', '4785853', '670111', '615101', '450260', '1170909', '6454219', '6446541', '5553361', '6429472', '1009546', '754104', '3754989', '619636', '2517081', '6407685', '607848', '3698258', '3091414', '2410921', '1161021', '1098887', '6381870', '951260', '3050196', '1671667', '3047950', '5552763', '1058557', '3801729', '6445772', '6168378', '6453379', '899298', '2670286', '336452', '3017057', '2059203', '1075862', '6321297', '67969', '2696337', '1253142', '462954', '2024200', '1713643', '6461112', '6428993', '5847553', '6928095', '355024', '5552558', '6431029', '2664636', '3488328', '2708599', '4871125', '976617', '4728788', '6101450', '6461227', '4671438', '6033821', '1387465', '6453399', '251999', '6310854', '6429520', '4689254', '6461015', '6439344', '6296509', '5357341', '6447419', '6427489', '3751289', '2539875', '2525923', '5533987', '5910925', '6446964', '1186980', '4662965', '6276507', '6438595', '969525', '6457161', '841715', '1331118', '1220342', '2323760', '6422168', '5551408', '2934584', '1396523', '1749733', '5545211', '1509230', '6430993', '582713', '5529698', '1466404', '797602', '133308', '6447467', '5542956', '3699531', '2729712', '2098712', '2153984', '2029825', '6460104', '720206', '5519810', '925777', '6429675', '5549965', '3385233', '6461240', '2431258', '5543202', '1050467', '5545273', '5534443', '1501849', '753992', '398924', '3782045', '1152424', '5522168', '921279', '6434250', '653702', '803252', '2551195', '6420366', '3188543', '316384', '620972', '5446260', '337059', '2371392', '1533635', '2851111', '6399940', '337759', '1150045', '1960856', '2639952', '5702993', '3280356', '4801392', '5550861', '5010700', '5549813', '6153362', '5545921', '1797062', '2869639', '3758719', '641922', '3960712', '1174420', '6400870', '2710183', '854047', '6412494', '5860511', '5544939', '342026', '4847104', '3537799', '5539241', '5867811', '5549717', '3048850', '1616995', '1404489', '6426291', '279124', '5492678', '348192', '921975', '6431609', '2524866', '6449261', '6411902', '6430233', '6012400', '3404357', '5481219', '1191039', '5013608', '1908717', '2902954', '6430960', '6208792', '1958170', '1099198', '375715', '6455839', '606338', '6075974', '6430178', '661002', '5459538', '3551568', '406846', '1854458', '2934539', '6448961', '6446550', '6422201', '1057885', '472521', '3014978', '258757', '5458488', '1343393', '2923146', '280249', '2738987', '3125246', '832096', '6454230', '4198328', '787615', '2127244', '1019071', '3382598', '2173370', '2223968', '3061884', '3568738', '5042855', '6446819', '5795250', '826971', '565878', '6447822', '6454993', '1655750', '2526221', '6446925', '1520382', '1383532', '872138', '1420479', '6310817', '6447455', '2891691', '2373098', '2962628', '2211790', '6423540', '1384704', '5522257', '3044200', '2435637', '5550130', '5539758', '634382', '1139121', '983258', '1053925', '989789', '5552354', '1192143', '1840780', '895784', '1278740', '6418157', '3017091', '6422096', '6401876', '1712963', '5545542', '5545487', '6422090', '5449604', '5485362', '2144160', '5291150', '6430566', '5001247', '6415363', '5549664', '827813', '6432345', '619384', '400453', '6428161', '3904274', '1501858', '2027648', '870606', '6446584', '5982093', '6446999', '623756', '5983666', '4099060', '6395513', '1114051', '6460916', '3320870', '2545211', '3048893', '1187099', '2587606', '164270', '1559108', '1005836', '6455566', '6245112', '2898212', '5552537', '6447980', '1507509', '6447992', '2224887', '2065431', '1657843', '5522145', '6389515', '4722497', '6420963', '2658414', '5779149', '1953562', '1867484', '5117246', '2549902', '6429748', '5221997', '1949094', '4715266', '1657308', '6456426', '6344625', '6431132', '5482264', '327842', '5504011', '1511542', '6422145', '1747247', '5428361', '6438686', '6423546', '5287750', '623056', '400391', '3485524', '6422065', '3567322', '1954048', '143147', '3281695', '2566402', '4900461', '5538965', '6428604', '4699078', '5544709', '600310', '5544831', '5402209', '5547318', '6757676', '6404336', '6005000', '6422633', '5553412', '5553147', '3382415', '6454375', '2328350', '6386036', '6427889', '5793928', '2047213', '5428521', '3725654', '1072583', '450452', '5545993', '100296', '5485883', '6646369', '2920800', '5545744', '174287', '1180268', '6432123', '604425', '2494080', '227604', '2485747', '5547030', '5522357', '6400161', '6447911', '6406846', '6461284', '6441287', '6392300', '5538987', '3136265', '5546133', '6446644', '6419340', '6423955', '1385510', '631753', '5535995', '1911994', '1078303', '5522054', '3168697', '342122', '6457372', '5062493', '5111554', '5992916', '6418111', '1323466', '1610138', '1616387', '622444', '6407573', '940875', '6416744', '729833', '1891852', '3862722', '3872474', '5522457', '2027512', '6419617', '2833559', '1823754', '5546630', '6401897', '6449514', '336660', '732683', '6453577', '2002277', '601999', '4318896', '1030142', '1258002', '6914136', '6453476', '6431116', '6018801', '4520672', '6405438', '866180', '6460897', '1122746', '3860006', '5535696', '6430937', '5542889', '2026177', '6453971', '833595', '1442716', '5534753', '405638', '2312521', '6426184', '605476', '3002357', '5052613', '747064', '5559442', '2491722', '1231060', '456820', '796618', '1096397', '6418092', '1998368', '6439931', '1472360', '5505793', '708821', '6247093', '2618360', '5544324', '5552218', '2388507', '3337066', '623766', '2393926', '2097317', '943872', '5549156', '1577257', '5403684', '6670214', '6422108', '1232062', '369838', '5535939', '581840', '6457459', '1016522', '1383591', '6408708', '3952065', '5505745', '3043725', '6427466', '2917676', '3915557', '5529773', '632986', '3540299', '322191', '322190', '1533619', '2399855', '2224980', '2660060', '1103295', '417810', '2524736', '4847053', '2681263', '648855', '1541336', '5547195', '1603140', '1627978', '115435', '1088433', '2613396', '2691487', '6453437', '6441095', '2159751', '1353017', '2758634', '6399578', '4214146', '1630179', '6421295', '920285', '768816', '1743364', '6422030', '660206', '794769', '5896097', '2380624', '2499846', '2924226', '5540187', '762454', '6453638', '5546856', '1830231', '410507', '227496', '6363916', '307671', '2356666', '6363035', '2009704', '5547455', '5539002', '5522637', '5546404', '6402115', '6385733', '3952939', '6090558', '5550425', '508008', '3150918', '6401184', '3154697', '6061284', '1068587', '790342', '4047244', '6413973', '199237', '5550511', '2587764', '6376933', '604627', '4873575', '5595680', '2975698', '6381450', '1554438', '1628406', '6430204', '2553505', '2556024', '3097057', '612669', '4745026', '2715980', '450489', '623759', '2952889', '4899797', '2849544', '2963337', '6453546', '5504537', '742725', '5040185', '6431005', '6385783', '5551353', '5544504', '2719721', '282896', '1861735', '6430520', '5533683', '2589011', '5552789', '6447442', '802609', '2359929', '2393355', '6095628', '2654432', '2229545', '5836167', '2268921', '1311524', '4523198', '4075623', '4667120', '4318759', '2258694', '1387860', '6423794', '5550458', '5209253', '5486369', '345781', '1799617', '343698', '6446998', '3162000', '2526817', '6418128', '6295113', '143276', '1269551', '5546174', '619419', '5486430', '5545368', '6423846', '5540112', '6430965', '4811486', '3016358', '6454047', '5519902', '3453739', '2614319', '5552257', '348199', '6432903', '1399819', '5515616', '6447655', '3614049', '627824', '6421188', '1559672', '331826', '4748594', '1575347', '1689706', '3165337', '3081120', '5546099', '1658486', '6411485', '2964163', '6430970', '3125401', '2676455', '4391873', '3225290', '4848471', '347820', '1146685', '1387992', '5708613', '2738689', '6418235', '2477888', '3499396', '6395278', '2737410', '5486050', '5542692', '904742', '5544219', '3083433', '1816719', '5053178', '714611', '3049538', '5547480', '6401234', '5534500', '2961704', '5538986', '3504117', '895120', '39508', '6461613', '857531', '2937329', '1322342', '1645066', '1546667', '1583604', '400225', '5519970', '6362356', '6422079', '368238', '3774066', '6427416', '31841', '5522694', '6427554', '3578141', '1488082', '5544771', '3908442', '423409', '5536010', '1262730', '2713623', '3180021', '2145510', '6430309', '2113664', '6397414', '211954', '6447543', '3762538', '6372607', '821420', '6395495', '6453516', '5545297', '5544696', '4780513', '6446522', '6424079', '6156748', '454285', '6428183', '6399816', '2845749', '6436557', '673545', '2535017', '2845748', '572538', '5535940', '6453810', '6395687', '6088654', '403060', '2917652', '1190153', '2731284', '4846297', '6361035', '2470203', '1164832', '5173233', '618731', '1192801', '1980018', '6381953', '6431040', '2710216', '937974', '829296', '6005105', '6357496', '6181292', '610951', '6447713', '876025', '2867772', '1786895', '3007047', '960453', '2112399', '331639', '6334822', '6376307', '3137856', '1231776', '6391471', '2768934', '3162100', '6181562', '5529881', '1648568', '654071', '6423897', '2004397', '6665746', '6362988', '754158', '1628388', '1007736', '1322385', '6391804', '6430719', '2354933', '2174912', '6012642', '6446619', '6422184', '2660541', '1376934', '654154', '6453562', '4967870', '5836055', '2569690', '6461388', '1695785', '5544205', '3129201', '6415086', '2132408', '6383355', '1630820', '5543550', '6414537', '5539776', '2484241', '1692552', '3165826', '2457116', '6384053', '3044537', '6455032', '2435488', '5552840', '1125313', '1226181', '6447035', '6418176', '530100', '2438086', '2444054', '5543935', '6395533', '315662', '6418666', '5552174', '1508566', '2736195', '3050147', '6429878', '527391', '6422208', '4393872', '6434378', '6422134', '353643', '502659', '3228619', '1200368', '1875690', '6398764', '4306008', '1695228', '6454137', '5542634', '1807643', '1015696', '3911553', '6429781', '1134371', '1384793', '2183151', '967202', '2184597', '6406670', '4569745', '855794', '6446510', '4364609', '6245328', '250100', '6446633', '1704245', '621770', '6430947', '1813268', '3444253', '878305', '2264707', '3363558', '2411979', '4885795', '1584978', '1139230', '5542558', '1280552', '398765', '2131438', '2516227', '2462718', '5937473', '1539735', '288630', '2952735', '992242', '997909', '5535816', '2245912', '5794449', '2940435', '5870488', '6423877', '3050172', '6422050', '1612808', '1884491', '5291106', '3176135', '3044058', '5544647', '5545223', '727663', '5839781', '2277839', '1481160', '1577857', '621809', '5390132', '176243', '836640', '6423685', '2401445', '5007060', '4244881', '1589355', '6382601', '5390033', '2333485', '6367915', '2952708', '5856869', '1127825', '3001636', '5488985', '1001720', '321874', '1737063', '1668560', '5539831', '3405394', '3149683', '2363889', '5024769', '1720299', '6454353', '6429950', '6447044', '3175798', '1868290', '1078509', '2417153', '5532640', '166859', '5550583', '3153162', '6453743', '6390199', '2982195', '6423560', '5546495', '2963176', '1288174', '1338760', '2739421', '3047762', '5535788', '1078321', '5550446', '3795422', '3015125', '6427123', '3083537', '2380484', '6423568', '1077554', '2039885', '5926710', '2171665', '3884857', '1503182', '1351850', '2276421', '2681339', '1275710', '2827291', '5457698', '810587', '6454878', '6399882', '5551904', '5042465', '4109230', '5551868', '4614183', '6439109', '5402429', '6383945', '1325504', '6348206', '2627944', '619548'] print len(all_userid),all_userid p = r.pipeline(transaction=False) for userid in all_userid: nickname = 'Bsfb%s'%userid key = 'hu:%s'%userid p.hmset(key,{'nickname':nickname}) p.execute()
def __init__(self, urls, username=None, password=None, redis_mode=RedisMode.STANDALONE, timeout=5, master_name=None, db=0, decode_responses=True): """ :param urls: redis 地址 ('hostname', 6379) 或 [('hostname', 6379),('hostname', 6378)] 或 [{"host": "127.0.0.1", "port": "7000"}, {"host": "127.0.0.1", "port": "7001"}] :param password: auth :param redis_mode: @see RedisMode :param timeout: :param master_name: :param db: :param decode_responses: """ self.urls = urls self.username = username self.password = password self.redis_mode = redis_mode self.timeout = timeout self.master_name = master_name self.db = db self.__conn = None self.__pool = None self.__cluster = None if self.redis_mode == RedisMode.SENTINEL or self.redis_mode == 1: if isinstance(urls, str): urls = [url.split(":") for url in urls.split(";")] if not isinstance(urls, List) and not isinstance(urls, Tuple): raise TypeError( "url : [('hostname', 6379),('hostname', 6378)]") sentinel = Sentinel(urls, socket_timeout=self.timeout, db=self.db, username=username, password=self.password, decode_responses=decode_responses) self.__pool = SentinelConnectionPool(master_name, sentinel, password=self.password) elif self.redis_mode == RedisMode.CLUSTER or self.redis_mode == 2: if isinstance(urls, str): def addr(url): _host, _port = url.split(":") return {"host": _host, "port": _port} urls = [addr(url) for url in urls.split(";")] if not isinstance(urls, List) and not isinstance(urls, Tuple): raise TypeError( 'url : [{"host": "127.0.0.1", "port": "7000"}, {"host": "127.0.0.1", "port": "7001"}]' ) self.__cluster = RedisCluster(startup_nodes=urls, decode_responses=decode_responses, socket_timeout=self.timeout, db=self.db, username=username, password=self.password) elif self.redis_mode == RedisMode.STANDALONE or self.redis_mode == 0: if isinstance(urls, str): urls = urls.split(":") if not isinstance(urls, List) and not isinstance(urls, Tuple): raise TypeError("url : ('hostname', 6379)") hostname, port = urls self.__pool = ConnectionPool(host=hostname, port=port, socket_timeout=self.timeout, password=self.password, db=self.db, username=username, decode_responses=decode_responses) else: raise TypeError('redis mode err')
def __init__(self,sentinel_list,service_name,db): self.sentinel = Sentinel(sentinel_list,socket_timeout=0.5) self.service_name = service_name self.db = db
#!/usr/bin/python # coding=utf-8 import sys from redis.sentinel import Sentinel sentinel = Sentinel([ ('10.5.5.194', 26379), ('10.5.5.155', 26379), ('10.5.5.128', 26379), ], socket_timeout=0.5) master = sentinel.master_for('mymaster', socket_timeout=0.5, password='******', db=0) slave = sentinel.slave_for('mymaster', socket_timeout=0.5, password='******', db=0) for name in range(50): # 判断是否所传参数对应的value值是否为空或者1,如果是设置为0 if slave.get(str(name)) is None or slave.get(str(name)) == "0": master.set(str(name), "1") f_do = sys.argv[1] + '.do' f_dat = sys.argv[1] + '.dat' f = open(f_dat, 'w') f.write('0' + '\n') f.write('success' + '\n')
from selenium.webdriver.support.ui import WebDriverWait from selenium import webdriver from bwjf_scrapy.util.webdriver_util import WebdriverUtil # from eie_info.settings import IP_PROXY # PROXIES = [{'host': '118.81.72.164', 'port': 9797}, {'host': '111.177.166.226', 'port': 9999}, # {'host': '101.236.42.63', 'port': 8866}, {'host': '114.99.253.216', 'port': 8118}, # {'host': '111.177.188.61', 'port': 9999}, {'host': '116.211.91.134', 'port': 8080}, # {'host': '221.2.174.3', 'port': 8060}] # pool=redis.ConnectionPool(host= IP_PROXY,port=6379,db=8) # r = redis.StrictRedis(connection_pool=pool) from redis.sentinel import Sentinel sentinel = Sentinel([('10.101.3.177', 26379), ('10.101.3.178', 26379), ('10.101.3.179', 26379)], socket_timeout=5) r = sentinel.master_for('mymaster', socket_timeout=5, db=8) PROXIES = r.srandmember("proxies", 1) proxy = PROXIES[0].decode('utf-8') PROXY = {} PROXY['host'] = eval(proxy)['ip'] PROXY['port'] = eval(proxy)['port'] class Crack(): def __init__(self, url, word, searchId, bowtonID): self.url = url # proxy = random.choice(PROXIES) # 打开带配置信息的phantomJS浏览器 # self.browser = webdriver.PhantomJS()
def create_app(config, enable_config_file=False): """ 创建应用 :param config: 配置信息对象 :param enable_config_file: 是否允许运行环境中的配置文件覆盖已加载的配置信息 :return: 应用 """ app = create_flask_app(config, enable_config_file) # 创建Snowflake ID worker from utils.snowflake.id_worker import IdWorker app.id_worker = IdWorker(app.config['DATACENTER_ID'], app.config['WORKER_ID'], app.config['SEQUENCE']) # 限流器 from utils.limiter import limiter as lmt lmt.init_app(app) # 配置日志 from utils.logging import create_logger create_logger(app) # 注册url转换器 from utils.converters import register_converters register_converters(app) from redis.sentinel import Sentinel _sentinel = Sentinel(app.config['REDIS_SENTINELS']) app.redis_master = _sentinel.master_for( app.config['REDIS_SENTINEL_SERVICE_NAME']) app.redis_slave = _sentinel.slave_for( app.config['REDIS_SENTINEL_SERVICE_NAME']) from rediscluster import StrictRedisCluster app.redis_cluster = StrictRedisCluster( startup_nodes=app.config['REDIS_CLUSTER']) # rpc # app.rpc_reco = grpc.insecure_channel(app.config['RPC'].RECOMMEND) # Elasticsearch app.es = Elasticsearch( app.config['ES'], # sniff before doing anything sniff_on_start=True, # refresh nodes after a node fails to respond sniff_on_connection_fail=True, # and also every 60 seconds sniffer_timeout=60) # socket.io app.sio_maneger = socketio.KombuManager(app.config['RABBITMQ'], write_only=True) # MySQL数据库连接初始化 from models import db db.init_app(app) # # 添加请求钩子 from utils.middlewares import jwt_authentication app.before_request(jwt_authentication) # 注册用户模块蓝图 from .resources.user import user_bp app.register_blueprint(user_bp) # 注册新闻模块蓝图 from .resources.news import news_bp app.register_blueprint(news_bp) # 注册通知模块 from .resources.notice import notice_bp app.register_blueprint(notice_bp) # 搜索 from .resources.search import search_bp app.register_blueprint(search_bp) return app
def sentinel(request, cluster): return Sentinel([("foo", 26379), ("bar", 26379)])
def __init__(self): # Global config... self.config = yaml.load(open('config.yaml', 'r', encoding='utf8')) # Logging... cfg = yaml.load(open('logging.yaml', 'r')) logging.config.dictConfig(cfg) # adding downstream if os.path.exists('downstream.yaml'): cfg = yaml.load(open('downstream.yaml', 'r', encoding='utf8')) self.config['downstream'] = cfg.get('downstream') handlers = [ (r"/health", ErrorHandler), # Public API (r"/order.do", OrderHandler), (r"/query.do", QueryHandler), # Callback (r"/callback/sk.do", CallbackSukaHandler), (r"/callback/ld.do", CallbackHandler), (r"/callback/ECServicesForADC.*", CallbackCmccHandler), (r"/callback/cmcc2/ECServicesForADC.*", CallbackCmccStatesHandler), (r"/callback/shili.do", CallbackShiliHandler), (r"/callback/quxun", CallbackQuxunHandler), (r"/callback/xicheng", XichengCallbackHandler), (r"/callback/aspire.do", CallbackAspireHandler), # (r"/callback/cmcc3.do", CallbackAspireECHandler), (r"/callback/cmcc3.do", CallbackAspireEC2Handler), (r"/callback/dahanfc.do", CallbackDahanfcHandler), (r"/callback/standard", CallbackStandardHandler), (r"/callback/yuechen.do", CallbackYuechenHandler), (r"/callback/esai.do", CallbackESaiHandler), (r"/callback/mopote", CallbackMopoteHandler), (r"/callback/cmccsn", CallbackCmccSnHandler), (r"/callback/cmccha", CallbackCmcchaHandler), (r"/callback/manual", CallbackManualHandler), (r"/callback/niukou", CallbackNiukouHandler), (r"/callback/xiaowo", CallbackXiaowoHandler), (r"/callback/migu", CallbackMiguHandler), (r"/callback/llreader", CallbackLlreaderHandler), (r"/callback/gmall", CallbackGmallHandler), (r"/callback/llfengbao", CallbackLlfengbaoHandler), (r"/callback/ruanyunbi", CallbackRuanyunbiHandler), (r"/callback/raiyi", CallbackRaiyiHandler), (r"/callback/yflow", CallbackYflowHandler), (r"/callback/zhjxzy", CallbackZhjxzyHandler), (r"/callback/xiamen_zyt", CallbackXiamenZytHandler), (r"/callback/ibumobile", CallbackIbumobileHandler), (r"/callback/faliuliang2", CallbackFaliuliang2Handler), (r"/callback/trafficweb", CallbackTrafficwebHandler), (r"/callback/bitfeng", CallbackBitfengHandler), (r"/callback/idatafocus", CallbackIdatafocusHandler), (r"/callback/zhixin", CallbackZhixinHandler), (r"/callback/shangtong", CallbackShangtongHandler), (r"/callback/jinfeng", CallbackJinfengHandler), (r"/callback/people", CallbackPeopleHandler), (r"/callback/telecom_gz", CallbackTelecomGzHandler), (r"/data/order", DataOrderHandler), (r"/data/callback", Callback21CnHandler), (r"/flow/callback.htm", Callback21CnHandler), # (r"/data/(prod|query|balance)", DataQueryHandler), (r"/balance.do", BalanceHandler), (r"/admin/fund", FundHandler), (r"/admin/reload", ReloadHandler), (r"/admin/config", ConfigHandler), (r"/admin/pricing", PricingHandler), (r"/admin/info", InfoHandler), (r"/.*", ErrorHandler), ] settings = dict( cookie_secret='VoGTaZcHTAKHF7cIL1/ZxFQxfNT/jEPNrE6KtgBQgVg=', debug=self.config['config']['debug'], ) tornado.web.Application.__init__(self, handlers, **settings) sentinels = [(c['ip'], c['port']) for c in self.config['cache']] self.sentinel = Sentinel(sentinels, socket_timeout=0.1, db=1, decode_responses=True) self.classifier = MobileClassifier('area_v4.bin') self.port = self.config['config']['port'] if 'connection' in self.config and 'glados' in self.config[ 'connection']: self.glados_client = motor.motor_tornado.MotorClient( self.config['connection']['glados'])
def __init__(self, ip_ports=None, db=None, user_pass=None, url=None, decode_responses=True, service_name=None, max_connections=32, **kwargs): """ redis的封装 Args: ip_ports: ip:port 多个可写为列表或者逗号隔开 如 ip1:port1,ip2:port2 或 ["ip1:port1", "ip2:port2"] db: user_pass: url: decode_responses: service_name: 适用于redis哨兵模式 """ # 可能会改setting中的值,所以此处不能直接赋值为默认值,需要后加载赋值 if ip_ports is None: ip_ports = setting.REDISDB_IP_PORTS if db is None: db = setting.REDISDB_DB if user_pass is None: user_pass = setting.REDISDB_USER_PASS if service_name is None: service_name = setting.REDISDB_SERVICE_NAME self._is_redis_cluster = False try: if not url: ip_ports = (ip_ports if isinstance(ip_ports, list) else ip_ports.split(",")) if len(ip_ports) > 1: startup_nodes = [] for ip_port in ip_ports: ip, port = ip_port.split(":") startup_nodes.append({"host": ip, "port": port}) if service_name: log.debug("使用redis哨兵模式") hosts = [(node["host"], node["port"]) for node in startup_nodes] sentinel = Sentinel(hosts, socket_timeout=3, **kwargs) self._redis = sentinel.master_for( service_name, password=user_pass, db=db, redis_class=redis.StrictRedis, decode_responses=decode_responses, max_connections=max_connections, **kwargs) else: log.debug("使用redis集群模式") self._redis = StrictRedisCluster( startup_nodes=startup_nodes, decode_responses=decode_responses, password=user_pass, max_connections=max_connections, **kwargs) self._is_redis_cluster = True else: ip, port = ip_ports[0].split(":") self._redis = redis.StrictRedis( host=ip, port=port, db=db, password=user_pass, decode_responses=decode_responses, max_connections=max_connections, **kwargs) else: self._redis = redis.StrictRedis.from_url( url, decode_responses=decode_responses) except Exception as e: raise else: if not url: log.debug("连接到redis数据库 %s db%s" % (ip_ports, db)) else: log.debug("连接到redis数据库 %s" % (url)) self._ip_ports = ip_ports self._db = db self._user_pass = user_pass self._url = url
#!/usr/bin/env python # -*- coding: utf-8 -*- # ---------------------------------------- # Just say "Hello world!". # ---------------------------------------- import time import datetime from redis.sentinel import Sentinel SENTINEL_NODES = ( ('localhost', 26379), ('localhost', 26380), ('localhost', 26381), ) sentinel = Sentinel(SENTINEL_NODES, socket_timeout=0.1) master = sentinel.master_for('master', socket_timeout=0.1, password="******") if '__main__' == __name__: while True: print datetime.datetime.now() print '--->' try: value = master.get('cur_time') print value except Exception, e: print e print "" time.sleep(1)
REDIS_SENTINEL_ENABLED = bool_from_env('REDIS_SENTINEL_ENABLED', False) REDIS_SOCKET_TIMEOUT = float(os.environ.get('REDIS_SOCKET_TIMEOUT', 1.0)) REDIS_CONNECT_TIMEOUT = float(os.environ.get('REDIS_CONNECT_TIMEOUT', 1.0)) REDIS_COMMAND_TIMEOUT = float(os.environ.get('REDIS_COMMAND_TIMEOUT', 10.0)) if REDIS_SENTINEL_ENABLED: from redis.sentinel import Sentinel REDIS_SENTINEL_HOSTS = get_sentinels( os.environ.get('REDIS_SENTINEL_HOSTS', None)) # noqa REDIS_CLUSTER_NAME = os.environ.get('REDIS_CLUSTER_NAME', 'ralph_ng') REDIS_SENTINEL_SOCKET_TIMEOUT = float( os.environ.get('REDIS_SENTINEL_SOCKET_TIMEOUT', 1.0)) # noqa sentinel = Sentinel(REDIS_SENTINEL_HOSTS, socket_timeout=REDIS_SENTINEL_SOCKET_TIMEOUT, password=REDIS_PASSWORD) REDIS_MASTER = sentinel.master_for(REDIS_CLUSTER_NAME) REDIS_CONNECTION = { 'SENTINELS': REDIS_SENTINEL_HOSTS, 'DB': int(os.environ.get('REDIS_DB', 0)), 'PASSWORD': REDIS_PASSWORD, 'TIMEOUT': REDIS_COMMAND_TIMEOUT, 'CONNECT_TIMEOUT': REDIS_CONNECT_TIMEOUT, } RQ_QUEUES = { 'default': { 'SENTINELS': REDIS_SENTINEL_HOSTS, 'MASTER_NAME': REDIS_CLUSTER_NAME, 'DB': int(os.environ.get('REDIS_DB', 0)),
# https://www.throwable.club/2019/10/07/redis-server-sentinel-install-guide/ import pprint from redis.sentinel import Sentinel sentinel = Sentinel([('127.0.0.1', '26379')]) master = sentinel.discover_master("doge-master") slaver = sentinel.discover_slaves("doge-master") pprint.pprint(master) pprint.pprint(slaver) master = sentinel.master_for("doge-master") slaver = sentinel.slave_for("doge-master") pprint.pprint(master.set("a", 1)) pprint.pprint(slaver.info("server").get("tcp_port"))
def _build_sentinel_client(config): # pylint: disable=too-many-locals """ Build a redis client with sentinel replication. :param config: Redis configuration properties. :type config: dict :return: A Wrapped redis-sentinel client :rtype: splitio.storage.adapters.redis.RedisAdapter """ sentinels = config.get('redisSentinels') if config.get('redisSsl', False): raise SentinelConfigurationException( 'Redis Sentinel cannot be used with SSL/TLS.') if sentinels is None: raise SentinelConfigurationException( 'redisSentinels must be specified.') if not isinstance(sentinels, list): raise SentinelConfigurationException( 'Sentinels must be an array of elements in the form of' ' [(ip, port)].') if not sentinels: raise SentinelConfigurationException( 'It must be at least one sentinel.') if not all(isinstance(s, tuple) for s in sentinels): raise SentinelConfigurationException( 'Sentinels must respect the tuple structure' '[(ip, port)].') master_service = config.get('redisMasterService') if master_service is None: raise SentinelConfigurationException( 'redisMasterService must be specified.') database = config.get('redisDb', 0) password = config.get('redisPassword', None) socket_timeout = config.get('redisSocketTimeout', None) socket_connect_timeout = config.get('redisSocketConnectTimeout', None) socket_keepalive = config.get('redisSocketKeepalive', None) socket_keepalive_options = config.get('redisSocketKeepaliveOptions', None) connection_pool = config.get('redisConnectionPool', None) encoding = config.get('redisEncoding', 'utf-8') encoding_errors = config.get('redisEncodingErrors', 'strict') decode_responses = config.get('redisDecodeResponses', True) retry_on_timeout = config.get('redisRetryOnTimeout', False) max_connections = config.get('redisMaxConnections', None) prefix = config.get('redisPrefix') sentinel = Sentinel(sentinels, db=database, password=password, socket_timeout=socket_timeout, socket_connect_timeout=socket_connect_timeout, socket_keepalive=socket_keepalive, socket_keepalive_options=socket_keepalive_options, connection_pool=connection_pool, encoding=encoding, encoding_errors=encoding_errors, decode_responses=decode_responses, retry_on_timeout=retry_on_timeout, max_connections=max_connections) redis = sentinel.master_for(master_service) return RedisAdapter(redis, prefix=prefix)
from redis.sentinel import Sentinel ''' @author: Administrator ''' cache_info='192.168.1.214:26379;192.168.1.215:26379;192.168.1.216:26379;192.168.1.217:26379;192.168.1.218:26379\ _192.168.1.219:6379;192.168.1.221:6379;192.168.1.223:6379;192.168.1.225:6379' sentinel_address=cache_info.split('_')[0].split(';') cache_address=cache_info.split('_')[1].split(';') seninel_ip=sentinel_address[0].split(':')[0] seninel_port=sentinel_address[0].split(':')[1] sentinel=Sentinel([(seninel_ip,seninel_port)]) sentinel_db1=Sentinel([(seninel_ip,seninel_port)],db=1)
password = REDIS_ARGS.get('password', '') cookies_db = REDIS_ARGS.get('cookies', 1) urls_db = REDIS_ARGS.get('urls', 2) broker_db = REDIS_ARGS.get('broker', 5) backend_db = REDIS_ARGS.get('backend', 6) id_name_db = REDIS_ARGS.get('id_name', 8) cookie_expire_time = get_cookie_expire_time() data_expire_time = REDIS_ARGS.get('expire_time') * 60 * 60 sentinel_args = REDIS_ARGS.get('sentinel', '') if sentinel_args: # default socket timeout is 2 secs master_name = REDIS_ARGS.get('master') socket_timeout = int(REDIS_ARGS.get('socket_timeout', 2)) sentinel = Sentinel([(args['host'], args['port']) for args in sentinel_args], password=password, socket_timeout=socket_timeout) cookies_con = sentinel.master_for(master_name, socket_timeout=socket_timeout, db=cookies_db) broker_con = sentinel.master_for(master_name, socket_timeout=socket_timeout, db=broker_db) urls_con = sentinel.master_for(master_name, socket_timeout=socket_timeout, db=urls_db) id_name_con = sentinel.master_for(master_name, socket_timeout=socket_timeout, db=id_name_db) else: host = REDIS_ARGS.get('host', '127.0.0.1')