コード例 #1
0
def run(ctx):
    """
    Run test server
    """

    redis(ctx)
    celery(ctx, True)
    _run(ctx, 'Starting dev server',
         '%s manage.py runserver' % sys.executable, pty=True)
コード例 #2
0
 def connect(self):
     if self.connection is None:
         self.connection = redis(host='localhost',
                                 port=6379,
                                 db=0,
                                 password='******')
     return self.connection
コード例 #3
0
        def _write_redis(partition, redis, expire, compress, max_pipeline_size,
                         mode):
            pipeline = redis().pipeline(transaction=False)
            add_to_pipeline = partial(pipeline.set,
                                      ex=expire,
                                      nx=(mode == 'ignore'))

            partition = iter(partition)
            while True:
                rows = islice(partition, max_pipeline_size)
                for row in rows:
                    row = row.asDict(recursive=True)

                    key = row.pop(key_name)
                    if group_by_key:
                        row = row[value_name]
                    if exclude_null_fields:
                        for null_field in list(f for f in row.keys()
                                               if row[f] is None):
                            del row[null_field]
                    data = bytes(ujson.dumps(row).encode('ascii'))
                    if compress:
                        data = compress(data)

                    add_to_pipeline(key, data)

                if not len(pipeline):
                    break

                pipeline.execute()
コード例 #4
0
def _brand_new_redis():
    global r
    if r is not None:
        r.stop()

    r = redis()
    r.start()
    return r.client()
コード例 #5
0
ファイル: trouter.py プロジェクト: liruikaiyao/workshop
#/usr/bin/python
# -*- coding: UTF-8 -*-
"""
使用tornado进行路由转发控制,将请求通过该服务进行转发。
当短时间出现大量的请求超过阈值的情况,服务会将过载部分的请求缓存在zeroMQ中,以便能缓慢的释放请求到应用服务器。
保障服务的正常运行。

版本、扩展与依赖:
python 2.6+
tornado4.1
pymongo2.8
redis(暂未使用)
zmq

"""
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.httpclient

import os
import sys
import urllib
import json
import datetime
import time
import re
import urlparse
import hashlib
import time
コード例 #6
0
ファイル: 3.py プロジェクト: AlexZeroX/mystuff
#!/usr/bin/env python
# coding=utf-8
"""
将第 0001 题生成的 200 个激活码保存到 Redis 非关系型数据库中
"""

import redis
__author__ = 'liuqi'

def redis():
    i = 0
    f = open("activation_code.txt", 'r')
    r = redis.Redis(host='localhost', port='6379')
    for line in f.readlines():
        r.zadd('codes', line.strip(), i)
        
if __name__ == "__main__":
    redis()

コード例 #7
0
 db_user.execute(sql, None)
 result = db_user.fetchall()
 if len(result) != 0:
     for x in result:
         user_id = x[0]
         mobile = x[1]
         source = x[2]
         sql = 'SELECT user_id,if_del FROM uc_user where mobile = %s' % mobile
         db_user.execute(sql, None)
         result = db_user.fetchall()
         # 账号恢复
         sql_1 = 'update uc_user_cancel_record set verify_state = 2 where user_id = %s' % user_id
         sql_2 = 'delete from uc_user_cancel_record_log where user_id = %s' % user_id
         db_user.execute(sql_1, None)
         db_user.execute(sql_2, None)
         r = redis(0)
         r.sadd('user_id_set_key', user_id)
         r.sadd('userid_mobile_set_key',
                str(user_id) + "__" + str(mobile))
         if len(result) > 1:  # 说明同一个mobile非单账号
             for y in result:
                 other_user_id = y[1]
                 if other_user_id != user_id:  # 需要逻辑删除的数据
                     sql_1 = 'update uc_user set if_del = 2 where user_id = %s' % other_user_id
                     sql_2 = 'update uc_user_real_name_authentication SET if_del = 2 WHERE user_id = %s' % other_user_id
                     sql_3 = 'update uc_account SET if_del = 2 WHERE user_id = %s' % other_user_id
                     sql_4 = 'delete from uc_user_online WHERE user_id = %s' % other_user_id
                     sql_5 = 'update uc_user_real_name_authentication set if_del = 2 where user_id =  %s;' % other_user_id
                     i = int(str(other_user_id)) % 2
                     if i == 0:
                         with DB(host="59.110.228.110",