PHP[018]:BitMap
BitMap算法 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25<?php
$redisHost = '127.0.0.1';
$redisPassWord = '';
$redisPort = 6379;
$redis = new \Redis();
$redis->connect($redisHost, $redisPort);
$redis->setOption(\Redis::OPT_READ_TIMEOUT, -1);
$redisPassWord && $redis->auth($redisPassWord);
$cacheKey = 'asdhasdhsjahdjahdjkahs';
$maxOffSet = 4294967296;
$redis->setBit($cacheKey, 7, 0);
// 高危。。。 如果值很小调用get 没有问题,如果值很大,则会出现没有反应的情况
$result = $redis->get($cacheKey);
$result = $redis->getbit($cacheKey, 13000);
$start = microtime(true);
sleep(1);
echo (microtime(true) - $start) . PHP_EOL;
$start = microtime(true);
$result = $redis->bitCount($cacheKey);
echo (microtime(true) - $start) . PHP_EOL;