def leave(request,id): redisdb = get_redis() """remove channels into user """ redis_channel_join_key = redisk.get_channel_join_key(request.session.session_key) redisdb.srem(redis_channel_join_key,id) """remove users into channel """ redis_channel_users_key = redisk.get_channel_users_key(id) redisdb.srem(redis_channel_users_key,request.user.pk) return HttpResponse()
def join(request,id): redisdb = get_redis() """put channels into user """ redis_channel_join_key = redisk.get_channel_join_key(request.session.session_key) redisdb.sadd(redis_channel_join_key,id) """put users into channel """ redis_channel_users_key = redisk.get_channel_users_key(id) redisdb.sadd(redis_channel_users_key,request.user.pk) return HttpResponse()
def users_json(request,id): redisdb = get_redis() redis_channel_users_key = redisk.get_channel_users_key(id) users = redisdb.smembers(redis_channel_users_key) keys = list(users) users = User.objects.in_bulk(keys).values() users_list = [] for key in users: users_list.append({ 'id':key.pk, 'username':key.username }) json = simplejson.dumps(users_list) return HttpResponse(json, mimetype='application/json')