def new(): if request.method == 'GET': return render_template('blog/new.html') title = request.form['title'] content = request.form['content'] tags = request.form['tags'] post_id = redis.incr('post:post-id') pipe = redis.pipeline() pipe.hmset( 'post:%s' % post_id, { "id": post_id, "title": title, "content": content, "content_markdown": markdown2.markdown(content, extras=['fenced-code-blocks']), "tags": tags }) for tag in tags.split(','): pipe.sadd('post:post-tags:%s' % tag.strip(), post_id) pipe.lpush('post:post-list', post_id) pipe.execute() return redirect(url_for('.detail', post_id=post_id))
def new(): if request.method == 'GET': return render_template('blog/new.html') title = request.form['title'] content = request.form['content'] tags = request.form['tags'] post_id = redis.incr('post:post-id') pipe = redis.pipeline() pipe.hmset('post:%s' % post_id, { "id": post_id, "title": title, "content": content, "content_markdown": markdown2.markdown(content, extras=['fenced-code-blocks']), "tags": tags }) for tag in tags.split(','): pipe.sadd('post:post-tags:%s' % tag.strip(), post_id) pipe.lpush('post:post-list', post_id) pipe.execute() return redirect(url_for('.detail', post_id=post_id))
def mark_online(user_id): now = int(time.time()) expires = now + (app.config['ONLINE_LAST_MINUTES'] * 60) + 10 all_users_key = 'online-users/%d' % now user_key = 'user-activity/%s' % user_id p = redis.pipeline() p.sadd(all_users_key, user_id) p.set(user_key, now) p.expireat(all_users_key, expires) p.expireat(user_key, expires) p.execute()
def mark_online(user_id): now = int(time.time()) expires = now + (ONLINE_LAST_MINUTES * 60) + 10 all_users_key = 'online-users/%d' % (now // 60) user_key = 'user-activity/%s' % user_id p = redis.pipeline() p.sadd(all_users_key, user_id) p.set(user_key, now) p.expireat(all_users_key, expires) p.expireat(user_key, expires) p.execute()
def __init__(self, key_prefix, limit, per, x_headers): self.reset = (int(time.time()) // per) * per + per self.key = key_prefix + str(self.reset) self.limit = limit self.per = per self.x_headers = x_headers p = redis.pipeline() p.incr(self.key) p.expireat(self.key, self.reset + self.expiration_window) self.current = min(p.execute()[0], limit)
def feature_redis(self): with redis.pipeline(transaction=False) as p: while not self.fe_queue.empty(): p.rpush('%s-feature' % datetime.datetime.now().date(), self.fe_queue.get(block=False)) p.execute()