from eventlet.green import socket import redis from engine import Engine redis_url = os.environ.get('REDIS_URL') or 'localhost' redis = redis.Redis(host=redis_url) pool = eventlet.GreenPool() COMMAND_DEADLINE = 6 MAX_ROUNDS = 500 START_ELO = 1000 MATCHMAKING_INTERVAL = 1 redis.ping() class Authenticator(object): def check(self, username, password): saved_password = redis.get("user:%s" % username) if not saved_password and os.environ.get( 'ALLOW_ACCOUNT_CREATION') == 'true': if len(username) > 100: return False redis.set("user:%s" % username, password) return True return saved_password and saved_password.decode() == password
# connection parameters port = opts.port hostname = opts.hostname password = opts.password database = opts.database debug = opts.debug try: redis = redis.StrictRedis( port=port, password=password, host=hostname, db=database ) if redis.ping(): status = "OK" message = "Success to ping-pong" else: status = "Critial" message = "Failed to ping-pong" output = OutputFormatHelpers.check_output_string( status, message ) print(output) except Exception as e: if debug:
import redis with redis.Redis() as redis: print(redis.ping())
parser.error("Does not accept any argument.") # connection parameters port = opts.port hostname = opts.hostname password = opts.password database = opts.database debug = opts.debug try: redis = redis.StrictRedis(port=port, password=password, host=hostname, db=database) if redis.ping(): status = "OK" message = "Success to ping-pong" else: status = "Critial" message = "Failed to ping-pong" output = OutputFormatHelpers.check_output_string(status, message) print(output) except Exception as e: if debug: print(e) the_type, value, tb = sys.exc_info() traceback.print_tb(tb)
from datetime import datetime, timezone import os from flask import Flask, request import redis import tldextract import validators app = Flask('API') redis_host = os.environ.get('REDIS_HOST', "localhost") redis = redis.Redis(host=redis_host, port=6379) is_db_connected = redis.ping() def check_valid_domain(link): parsed = tldextract.extract(link) domain = ".".join([parsed.domain, parsed.suffix]) if "://" in link: assert validators.url(link), "'links' contain an invalid link" else: assert validators.domain(domain), "'links' contain an invalid link" return domain def list_isinstance(lst, tp): res = list(map(lambda x: isinstance(x, tp), lst)) return all(res) @app.route("/visited_links", methods=["POST"])
import redis redis = redis.Redis() try (redis.ping()): print("ok") else: print("not ok")
def start(args, **todo_options): todo = { 'directory': True, 'logging': True, 'daemonise': True, 'redis': True, 'database': True, 'rabbitmq': True, } for item in todo_options.keys(): if item in todo: todo[item] = todo_options[item] if isinstance(args, dict): args = AttrDict(args) config_obj = InceptConfig() global config_data config_data = config_obj.get() if todo['directory']: if args.directory: working_directory = args.directory else: working_directory = os.getcwd() site.addsitedir(working_directory) if todo['logging']: if 'logging' in config_data: global logging logging_obj = InceptLogging(config_data) logging = logging_obj.logging _get_filenos_from_logging(logging) if todo['daemonise']: # daemonise if required to do so if args.background: import daemon import daemon.pidfile daemon_args = {} daemon_args['working_directory'] = working_directory if args.pidfile: daemon_args['pidfile'] = daemon.pidfile.PIDLockFile( args.pidfile) if 'logging' in config_data: # preserve any files opened by logging # this won't preserve STDOUT/STDERR, even if # logging said to use them. daemon_args['files_preserve'] = _get_filenos_from_logging( Incept.logging) global daemon_context daemon_context = daemon.DaemonContext(**daemon_args) daemon_context.open() if todo['redis']: if 'redis' in config_data: import redis global redis redis = redis.Redis(**config_data['redis']) redis.ping() if todo['database']: if 'database' in config_data: from sqlalchemy import create_engine db_config = {} for key, value in config_data['database'].items(): if key not in ['url']: db_config[key] = value global database_engine global database database_engine = create_engine(config_data['database']['url'], **db_config) database = database_engine.connect() if todo['rabbitmq']: if 'rabbitmq' in config_data: import pika for required in ['username', 'password', 'host']: if required not in config_data['rabbitmq']: raise KeyError('%s not in RabbitMQ config' % (required)) credentials = pika.PlainCredentials( config_data['rabbitmq']['username'], config_data['rabbitmq']['password']) try: vhost = config_data['rabbitmq']['vhost'] except KeyError: vhost = '/' parameters = pika.ConnectionParameters( host=config_data['rabbitmq']['host'], credentials=credentials, virtual_host=vhost) global rabbitmq rabbitmq = pika.BlockingConnection(parameters)
def redis_check(): try: redis.ping() return True except: return False