Home > Backend Development > PHP Tutorial > redis implements serializer

redis implements serializer

WBOY
Release: 2016-08-08 09:21:18
Original
2069 people have browsed it

Auto incrementing the ID value through mysql's auto increment may leak some sensitive data.

For example, the user_id of the user table is auto-incremented, and the id value displayed in the URL may reveal the real number of users of the website.

The following code implements a simple number generator through PHP and redis' incrby. The code is as follows:

function get_id($type, $server_ip, $server_port, $key) {
    $init_num = 0;
    $redis= new Redis();
    $redis->connect($server_ip, $server_port);
    $var = $redis->exists($key);
    if($var == 0) {
        $redis->set($key,$init_num);
    }
    $incr_num = rand(1,50); //增量为随机数
    $var = $redis->incrby($key, $incr_num);
    $redis->close();
    return $var;
}
Copy after login

The above introduces the redis implementation of the number dispatcher, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template