示例#1
0
 def setup(self, app):
     for other in app.plugins:
         if not isinstance(other, RedisShardPlugin): continue
         if other.keyword == self.keyword:
             raise PluginError("Found another redis shard plugin with "\
                     "conflicting settings (non-unique keyword).")
     if self.redisdb is None:
         self.redisdb = RedisShardAPI(self.config)
示例#2
0
    def reconnect_redis(self):
        if self.shared_client and Storage.storage:
            return Storage.storage

        storage = RedisShardAPI(self.context.config.REDIS_SERVERS,
                                hash_method='md5')

        if self.shared_client:
            Storage.storage = storage
        return storage
示例#3
0
    def reconnect_redis(self):
        '''Reconnect to redis.
        :return: Redis client instance
        :rettype: redis.Redis
        '''

        if self.shared_client and Storage.storage:
            return Storage.storage

        storage = RedisShardAPI(self.context.config.REDIS_SERVERS,
                                hash_method='md5')

        if self.shared_client:
            Storage.storage = storage
        return storage
示例#4
0
 def decorator(*args, **kwargs):
     servers = current_app.config.get("REDIS_SHARD_URL")
     client = RedisShardAPI(servers, hash_method='md5')
     now = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S")
     ip = request.remote_addr
     key = "%s{%s}" % (ip, now)
     client.incr(key)
     if client.get(key):
         num = int(client.get(key))
     else:
         num = 0
     client.expire(key, 10)
     if num > times:
         return jsonify(
             dict(code=40003,
                  msg='warning: Refused to too many requests !'))
     return f(*args, **kwargs)
示例#5
0
 def setUp(self):
     self.client = RedisShardAPI(**settings)
     self.clear_db()
示例#6
0
 def setUp(self):
     self.client = RedisShardAPI(servers)
     self.clear_db()
示例#7
0
        'port': 6379,
        'db': 0
    },
    #{'name':'server5','host':'127.0.0.1','port':14000,'db':0},
    #{'name':'server6','host':'127.0.0.1','port':15000,'db':0},
]

########NEW FILE########
__FILENAME__ = myapp
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from redis_shard.shard import RedisShardAPI
from config import servers
import time

client = RedisShardAPI(servers)
client.set('test', 1)
print client.get('test')
client.zadd('testset', 'first', 1)
client.zadd('testset', 'second', 2)
print client.zrange('testset', 0, -1)
print client.zrank('testset', 'second')
print client.zrank('testset2', 'second')

client.set('foo', 2)
client.set('a{foo}', 5)
client.set('b{foo}', 5)
client.set('c{foo}', 5)
client.set('{foo}d', 6)
client.set('{foo}e', 7)
client.set('e{foo}f', 8)
示例#8
0
 def init_app(self, app):
     servers = app.config.get("REDIS_SHARD_URL")
     client = RedisShardAPI(servers, hash_method='md5')
     self._cache = client
     return client
示例#9
0
        'password': '******',
        'db': '0'
    }
redis_info_2 = {
    'host': 'mb.y.redis.sohucs.com',
    'port': '22829',
    'password': '******',
    'db': '0'
}
servers = [
    {'name': 'server1', 'host': 'mb.y.redis.sohucs.com', 'port': 22812, 'db': 0,
     'password': '******'},
    {'name': 'server2', 'host': 'mb.y.redis.sohucs.com', 'port': 22829, 'db': 0,
     'password': '******'}
    ]
client = RedisShardAPI(servers, hash_method='md5')

def connect_db(host, port, password, db):
    pool = redis.ConnectionPool(host=host, port=port, password=password, decode_responses=True, db=db)
    r = redis.StrictRedis(connection_pool=pool)
    return r


def recommend(clk_cid):
    # 得到点击历史
    clk_his = user_clk_his[clk_cid]

    # print '点击历史', clk_his

    # 建立召回列表
    recall_list = []
示例#10
0
        'name': 'feed19',
        'host': 'feedproxy',
        'port': 6319,
        'db': 0
    },
    {
        'name': 'feed20',
        'host': 'feedproxy',
        'port': 6320,
        'db': 0
    },
]

FEED_KEY = "{feed%(user_id)s}:list"

old_shard = RedisShardAPI(old_servers)
new_shard = RedisShardAPI(new_servers)


def main():
    parser = argparse.ArgumentParser(description='Reshard newsfeed instance')
    parser.add_argument('--start',
                        type=int,
                        required=True,
                        help='start user id')
    parser.add_argument('--end', type=int, required=True, help='start user id')
    parser.add_argument('--show_only',
                        type=bool,
                        default=False,
                        help='only showw migrate process')
    parser.add_argument('--delete',
示例#11
0
redis_url = urlparse(Configuration.REDIS_URL)
redis = Redis(host=redis_url.hostname,
              port=redis_url.port,
              password=redis_url.password)
scheduler = Scheduler('scheduled', interval=60, connection=redis)

wigo_queued_db = WigoQueuedDB(redis) if Configuration.RDBMS_REPLICATE else None
wigo_rdbms = WigoRdbms()

if Configuration.ENVIRONMENT != 'test':
    servers = []
    for index, redis_url in enumerate(Configuration.REDIS_URLS):
        parsed = urlparse(redis_url)
        servers.append({
            'name': 'redis_{}'.format(index),
            'host': parsed.hostname,
            'port': parsed.port,
            'password': parsed.password
        })

    from redis_shard import shard

    shard.SHARD_METHODS = set(shard.SHARD_METHODS)
    shard.SHARD_METHODS.add('zscan')
    shard.SHARD_METHODS.add('zscan_iter')

    sharded_redis = RedisShardAPI(servers, hash_method='md5')
    wigo_db = WigoRedisDB(sharded_redis, wigo_queued_db)
else:
    wigo_db = WigoRedisDB(redis, wigo_queued_db)
示例#12
0
文件: setting.py 项目: wing1000/wb3
        'port': 10000,
        'db': 0
    },
    'node2': {
        'host': '127.0.0.1',
        'port': 11000,
        'db': 0
    },
    'node3': {
        'host': '127.0.0.1',
        'port': 12000,
        'db': 0
    },
}

redis = RedisShardAPI(RedisServers)

PATH = os.getcwd()
favicon_path = os.path.join(PATH, 'favicon.ico')

settings = {
    'debug': True,
    'static_path': os.path.join(PATH, 'static'),
}
Engine = tenjin.Engine(layout='_layout2.html',
                       path=[os.path.join('views', theme)
                             for theme in THEMES] + ['views'],
                       cache=tenjin.MemoryCacheStorage(),
                       preprocess=True)
# if __name__ == "__main__":
#     html= Engine.render('home.html', {
示例#13
0
 def get_cache_redis(self):
     return RedisShardAPI(REDIS_CONFIG_CACHE)
示例#14
0
 def __init__(self, server):
     try:
         self.client = RedisShardAPI(server)
     except:
         raise Exception, 'Failed to connect redis sharding'
示例#15
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from redis_shard.shard import RedisShardAPI
from config import servers
import time

client = RedisShardAPI(servers)
client.set('test', 1)
print client.get('test')
client.zadd('testset', 'first', 1)
client.zadd('testset', 'second', 2)
print client.zrange('testset', 0, -1)
print client.zrank('testset', 'second')
print client.zrank('testset2', 'second')

client.set('foo', 2)
client.set('a{foo}', 5)
client.set('b{foo}', 5)
client.set('c{foo}', 5)
client.set('{foo}d', 6)
client.set('{foo}e', 7)
client.set('e{foo}f', 8)
print client.get_server_name('foo')
print client.get_server_name('c{foo}')
print client.get_server_name('{foo}d')
print client.get_server_name('{foo}e')
print client.get_server_name('e{foo}f')
t0 = time.time()
print client.tag_keys('*{foo}*')
t1 = time.time()
print t1 - t0