def process(command):
    client = RedisClient(host='localhost', port=6391)
    client.select(3)
    #get notices
    notices = client.smembers('notices')
    print notices
    return reply(True, notices, command)
def process(command):
    proposal_id = command['proposal_id']
    client = RedisClient(host='localhost', port=6391)
    client.select(2)
    #get proposal
    #get proposal comment

    return reply(True, command, proposal_title_list)
Example #3
0
def send_loop():
    c = RedisClient()
    sleep(1)

    print 'SEND S', time.time()

    for x in xrange(500):
        c.publish("foo", "bar")

    print 'SEND E', time.time()
Example #4
0
def send_loop():
    c = RedisClient()
    sleep(1)

    print 'SEND S', time.time()

    for x in xrange(500):
        c.publish("foo", "bar")

    print 'SEND E', time.time()
Example #5
0
def take_lock():
    global counter
    client = RedisClient('localhost', 6379)
    try:
        with RedisLock(client, key, timeout=lock_timeout) as lock:
            v = client.get(incr_key)
            sleep(random.random() * sleep_factor)
            client.set(incr_key, int(v) + 1)
        counter += 1
    except LockNotAcquired:
        pass
Example #6
0
def take_lock():
    global counter
    client = RedisClient('localhost', 6379)
    try:
        with RedisLock(client, key, timeout=lock_timeout) as lock:
            v = client.get(incr_key)
            sleep(random.random() * sleep_factor)
            client.set(incr_key, int(v) + 1)
        counter += 1
    except LockNotAcquired:
        pass
def process(command):
    user_name = command["user_name"]
    password = command["password"]
    print user_name
    print password
    client = RedisClient(host='localhost', port=6391)
    client.select(1)
    pw = client.hget('user_name', user_name)
    if pw == password:
	    return reply(True, 10001, 1, command)
    else:
        print "password is not right : %r" % user_name
    return reply(False, 0, 0, command)
def process(command):
    proposal_id = command['proposal_id']

    client = RedisClient(host='localhost', port=6391)
    client.select(2)
    comments = []
    comment_id = "comment_" + str(proposal_id)
    comment_list = client.lrange(comment_id, 0, -1)
    for comment in comment_list:
        result = comment.split('^')
        if len(result)>=3:
            comments.append(Comment(result[0], result[1], result[2]).data_dict)
    return reply(True, command, comments)
def process(command):
    user_name = command["user_name"]
    password = command["password"]
    print user_name
    print password
    client = RedisClient(host='localhost', port=6391)
    client.select(1)
    pw = client.hget('user_name', user_name)
    if pw == password:
	    return {"result":True, "user_id":10001, "privilege":1}
    else:
        print "password is not right : %r" % user_name
    return {"result":False, "user_id":0, "privilege":0}
def process(command):
    notice = command["content"]
    client = RedisClient(host='localhost', port=6391)
    client.select(3)
    #Write notice to redis
    #Set
    print notice.encode('UTF8')
    result = client.sadd('notices', notice.encode('UTF8'))
    print "sadd result", result
    if result:
        return reply(True, command)
    else:
        return reply(False, command)
def process(command):
    proposal_id = command['proposal_id']
    comment = command['comment']
    user_name = command['user_name']

    client = RedisClient(host='localhost', port=6391)
    client.select(2)
    #check propsoal 
    key = "proposal" + str(proposal_id)
    print "key %r" % key
    result = client.exists(key)
    if not result:
       return {'command': command['command'], 'sequence_id': command['sequence_id'], "result": result}

    #sadd
    comment_id = "comment_" + str(proposal_id)
    client.lpush(comment_id, user_name+'^'+comment+'^'+str(time.time()))

    comments = []
    comment_list = client.lrange(comment_id, 0, -1)
    for comment in comment_list:
        result = comment.split('^')
        if len(result)>=3:
            comments.append(Comment(result[0], result[1], result[2]).data_dict)
    return reply(True, command, comments)
Example #12
0
def main():
    client = RedisClient('localhost', 6379)
    client.delete(key)
    client.set(incr_key, 0)

    for _ in xrange(500):
        fork(take_lock)
        if random.random() > 0.1:
            sleep(random.random() / 10)
    sleep(2)
    assert counter == int(client.get(incr_key)), 'Incr failed!'
    quickstop()
Example #13
0
def main():
    client = RedisClient('localhost', 6379)
    client.delete(key)
    client.set(incr_key, 0)

    for _ in xrange(500):
        fork(take_lock)
        if random.random() > 0.1:
            sleep(random.random() / 10)
    sleep(2)
    assert counter == int(client.get(incr_key)), 'Incr failed!'
    quickstop()
def process(command):
    #get account id
    client = RedisClient('localhost', 6391)
    client.select(1)
    accout_id_key = "accout_id"
    accout_id_lock = "accout_id_lock"
    try:
        with RedisLock(client, accout_id_lock, timeout=lock_timeout) as lock:
            accout_id = client.get(accout_id_key)
            client.set(accout_id_key, int(accout_id) + 1)
    except LockNotAcquired:
        pass
    #create account: name password privilege

    return {"result":False, "user_id":0, "privilege":0}
def process(command):
    proposal_id = command['proposal_id']
    print "proposal_id %r" %proposal_id
    client = RedisClient(host='localhost', port=6391)
    client.select(2)
    proposal_key = "proposal" + str(proposal_id)
    print proposal_key
    value = client.hgetall(proposal_key)
    print value 
    client.select(4)
    key = "reconsider" + str(proposal_id)
    client.hset(key, 'title', value['title'])
    client.hset(key, 'state', value['state'])
    client.hset(key, 'content', value['content'])
    client.hset(key, 'type', 1)
    client.hset(key, 'time', value['time'])
    client.hset(key, 'agree_count', 0)
    client.hset(key, 'disagree', 0)
    reconsiderTitle = ReconsiderTitle(value['title'], value['state'], proposal_id, value['content'], 0, 0)
    client.lpush("list", proposal_id)
    #create reconsider

    #delete proposal
    client.select(2)
    client.delete(proposal_key)
    client.lrem("list", proposal_id, 1)
    return reply(True, command, reconsiderTitle)
def process(command):
    client = RedisClient(host='localhost', port=6391)
    client.select(2)
    proposal_id_lock = "proposal_id_lock"
    proposal_id_key = "uuid"
    proposal_id = 0
    #get proposal id
    try:
        with RedisLock(client, proposal_id_lock, timeout=lock_timeout) as lock:
            proposal_id = client.get(proposal_id_key)
            client.set(proposal_id_key, int(proposal_id) + 1)
    except LockNotAcquired:
        return reply(False, command)
    proposeal_key = "proposal" + str(proposal_id)
    client.hset(proposeal_key, 'title', command['title'])
    client.hset(proposeal_key, 'content', command['content'])
    #提议: 复议/未复议
    #复议: 赞同/反对
    #会议: 进行中/已完成/为开始
    #决议: 执行
    client.hset(proposeal_key, 'state', 0)
    client.hset(proposeal_key, 'type', 0)
    client.hset(proposeal_key, 'time', time.time())
    client.lpush("list", proposal_id)
    #set proposal title
    #proposal_id: title: ***
    #             content: ***
    #             state: ***
    #             time:
    #SORT list get proposal_*->time
    #sort list by proposal*->time get proposal*->content
    return reply(True, command, proposal_id)