开发环境初始化(centos7)

Posted in 2016-12-26 14:56 | Category: Linux | Tags: centos redis linux python mysql

新建用户

[root@localhost]# passwd honmaple
Changing password for user honmaple.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.

安装mysql

参考步骤: http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

下载安装

[root@localhost]# wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
[root@localhost]# rpm -Uvh mysql57-community-release-el6-8.noarch.rpm
[root@localhost]# yum list installed | grep mysql
mysql57-community-release.noarch     el6-8                          installed
[root@localhost]# yum install mysql-community-server
错误:软件包:2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
          需要:libmysqlclient.so.18(libmysqlclient_18)(64bit …

redis记录用户操作

Posted in 2016-1-10 16:36 | Category: Python | Tags: redis linux

必须得记下来,否则等那天看到又要浪费时间了,主要记录访问时间这里

    '''记录访问的时间'''
    now_time = int(time()) #首先得到当前时间戳 
    '''查询上次访问的时间和最近访问的时间'''
    query_last_time = redis_data.zscore(visited_users,'last_time')
    query_now_time = redis_data.zscore(visited_users,'time')
    '''判断查询是否为空,一般是第一次访问还未记录的IP'''
    if query_last_time is None:
        query_last_time = now_time
        pipe.zadd(visited_users,query_last_time,'last_time')
    if query_now_time is None:
        query_now_time = now_time
    '''将当前时间与last_time进行对比,十分钟之内不记录'''
    if now_time - query_last_time >= 600:
        '''这里类似交换更新数据,把query_now_time变成last_time,把now_time更新'''
        pipe.zadd(visited_users,query_now_time,'last_time')
        pipe.zadd(visited_users,now_time,'time')
    else:
        pipe.zadd(visited_users,now_time,'time')