public function testHScan() { if (version_compare($this->version, "2.8.0", "lt")) { $this->markTestSkipped(); return; } // Never get empty sets $this->redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); $this->redis->del('hash'); $i_foo_mems = 0; for ($i = 0; $i < 100; $i++) { if ($i > 3) { $this->redis->hset('hash', "member:{$i}", "value:{$i}"); } else { $this->redis->hset('hash', "foomember:{$i}", "value:{$i}"); $i_foo_mems++; } } // Scan all of them $it = NULL; while ($arr_keys = $this->redis->hscan('hash', $it)) { $i -= count($arr_keys); } $this->assertEquals(0, $i); // Scan just *foomem* (should be 4) $it = NULL; while ($arr_keys = $this->redis->hscan('hash', $it, '*foomember*')) { $i_foo_mems -= count($arr_keys); foreach ($arr_keys as $str_mem => $str_val) { $this->assertTrue(strpos($str_mem, 'member') !== FALSE); $this->assertTrue(strpos($str_val, 'value') !== FALSE); } } $this->assertEquals(0, $i_foo_mems); }
/** * Get or set setting * * @param string $name * @param string|int $value * @return mixed */ public function setting($name, $value = null) { if ($value) { $this->client->hset('q:settings', $name, $value); return $this; } return $this->client->hget('q:settings', $name); }
public function testHashes() { $this->redis->delete('h', 'key'); $this->assertTrue(0 === $this->redis->hLen('h')); $this->assertTrue(1 === $this->redis->hSet('h', 'a', 'a-value')); $this->assertTrue(1 === $this->redis->hLen('h')); $this->assertTrue(1 === $this->redis->hSet('h', 'b', 'b-value')); $this->assertTrue(2 === $this->redis->hLen('h')); $this->assertTrue('a-value' === $this->redis->hGet('h', 'a')); // simple get $this->assertTrue('b-value' === $this->redis->hGet('h', 'b')); // simple get $this->assertTrue(0 === $this->redis->hSet('h', 'a', 'another-value')); // replacement $this->assertTrue('another-value' === $this->redis->hGet('h', 'a')); // get the new value $this->assertTrue('b-value' === $this->redis->hGet('h', 'b')); // simple get $this->assertTrue(FALSE === $this->redis->hGet('h', 'c')); // unknown hash member $this->assertTrue(FALSE === $this->redis->hGet('key', 'c')); // unknownkey // hDel $this->assertTrue(1 === $this->redis->hDel('h', 'a')); // 1 on success $this->assertTrue(0 === $this->redis->hDel('h', 'a')); // 0 on failure $this->redis->delete('h'); $this->redis->hSet('h', 'x', 'a'); $this->redis->hSet('h', 'y', 'b'); $this->assertTrue(2 === $this->redis->hDel('h', 'x', 'y')); // variadic // hsetnx $this->redis->delete('h'); $this->assertTrue(TRUE === $this->redis->hSetNx('h', 'x', 'a')); $this->assertTrue(TRUE === $this->redis->hSetNx('h', 'y', 'b')); $this->assertTrue(FALSE === $this->redis->hSetNx('h', 'x', '?')); $this->assertTrue(FALSE === $this->redis->hSetNx('h', 'y', '?')); $this->assertTrue('a' === $this->redis->hGet('h', 'x')); $this->assertTrue('b' === $this->redis->hGet('h', 'y')); // keys $keys = $this->redis->hKeys('h'); $this->assertTrue($keys === array('x', 'y') || $keys === array('y', 'x')); // values $values = $this->redis->hVals('h'); $this->assertTrue($values === array('a', 'b') || $values === array('b', 'a')); // keys + values $all = $this->redis->hGetAll('h'); $this->assertTrue($all === array('x' => 'a', 'y' => 'b') || $all === array('y' => 'b', 'x' => 'a')); // hExists $this->assertTrue(TRUE === $this->redis->hExists('h', 'x')); $this->assertTrue(TRUE === $this->redis->hExists('h', 'y')); $this->assertTrue(FALSE === $this->redis->hExists('h', 'w')); $this->redis->delete('h'); $this->assertTrue(FALSE === $this->redis->hExists('h', 'x')); // hIncrBy $this->redis->delete('h'); $this->assertTrue(2 === $this->redis->hIncrBy('h', 'x', 2)); $this->assertTrue(3 === $this->redis->hIncrBy('h', 'x', 1)); $this->assertTrue(2 === $this->redis->hIncrBy('h', 'x', -1)); $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'x', "not-a-number")); $this->assertTrue("2" === $this->redis->hGet('h', 'x')); $this->redis->hSet('h', 'y', 'not-a-number'); $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'y', 1)); if (version_compare($this->version, "2.5.0", "ge")) { // hIncrByFloat $this->redis->delete('h'); $this->assertTrue(1.5 === $this->redis->hIncrByFloat('h', 'x', 1.5)); $this->assertTrue(3.0 === $this->redis->hincrByFloat('h', 'x', 1.5)); $this->assertTrue(1.5 === $this->redis->hincrByFloat('h', 'x', -1.5)); $this->redis->hset('h', 'y', 'not-a-number'); $this->assertTrue(FALSE === $this->redis->hIncrByFloat('h', 'y', 1.5)); } // hmset $this->redis->delete('h'); $this->assertTrue(TRUE === $this->redis->hMset('h', array('x' => 123, 'y' => 456, 'z' => 'abc'))); $this->assertTrue('123' === $this->redis->hGet('h', 'x')); $this->assertTrue('456' === $this->redis->hGet('h', 'y')); $this->assertTrue('abc' === $this->redis->hGet('h', 'z')); $this->assertTrue(FALSE === $this->redis->hGet('h', 't')); // hmget $this->assertTrue(array('x' => '123', 'y' => '456') === $this->redis->hMget('h', array('x', 'y'))); $this->assertTrue(array('z' => 'abc') === $this->redis->hMget('h', array('z'))); $this->assertTrue(array('x' => '123', 't' => FALSE, 'y' => '456') === $this->redis->hMget('h', array('x', 't', 'y'))); $this->assertFalse(array(123 => 'x') === $this->redis->hMget('h', array(123))); $this->assertTrue(array(123 => FALSE) === $this->redis->hMget('h', array(123))); // hmget/hmset with numeric fields $this->redis->del('h'); $this->assertTrue(TRUE === $this->redis->hMset('h', array(123 => 'x', 'y' => 456))); $this->assertTrue('x' === $this->redis->hGet('h', 123)); $this->assertTrue('x' === $this->redis->hGet('h', '123')); $this->assertTrue('456' === $this->redis->hGet('h', 'y')); $this->assertTrue(array(123 => 'x', 'y' => '456') === $this->redis->hMget('h', array('123', 'y'))); // check non-string types. $this->redis->delete('h1'); $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('x' => 0, 'y' => array(), 'z' => new stdclass(), 't' => NULL))); $h1 = $this->redis->hGetAll('h1'); $this->assertTrue('0' === $h1['x']); $this->assertTrue('Array' === $h1['y']); $this->assertTrue('Object' === $h1['z']); $this->assertTrue('' === $h1['t']); }
public function hset($prefix, $key, $value, $dependency = null) { if ($dependency !== null) { $dependency->evaluateDependency(); } $data = array($value, $dependency); return parent::hset($this->generateUniqueKey($prefix), $key, serialize($data)); }
/** * @inheritdoc */ protected function doLog($ident, $originalId, array $context) { $this->redis->hset($ident, $originalId, json_encode($context)); }
function setCache($type, $arrData = array()) { switch ($type) { case 'Campaign': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'Campaign'; $arrCampaign = $redis->hgetall($cacheKey); $servername = DB_HOST . ":" . DB_PORT; $username = DB_USERNAME; $password = DB_PASSWORD; $dbname = DB_NAME; $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrCampaign[$data['id']]); $campaign_id = $data['id']; $campConvKey = "CampConv_{$campaign_id}"; $arrCampConv = $redis->hgetall($campConvKey); $sql = <<<EOF SELECT id, campaign_id FROM pt_conversion WHERE status = 1 AND campaign_id = {$campaign_id} EOF; $result = $conn->query($sql); $arrTmp = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $arrTmp[] = $row; } } foreach ($arrTmp as $item) { $redis->hSet($campConvKey, $item['id'], $item['id']); if (!empty($arrCampConv[$item['id']])) { unset($arrCampConv[$item['id']]); } } if (!empty($arrCampConv)) { foreach ($arrCampConv as $key => $val) { $redis->hdel($campConvKey, $key); } } } } if (!empty($arrCampaign)) { foreach ($arrCampaign as $id => $campaign) { $redis->hdel($cacheKey, $id); $redis->del("CampConv_{$id}"); } } break; case 'Flight': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'Flight'; $arrFlight = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $data['country'] = json_decode($data['country']); $data['province'] = json_decode($data['province']); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrFlight[$data['id']]); } } if (!empty($arrFlight)) { foreach ($arrFlight as $id => $flight) { $redis->hdel($cacheKey, $id); } } break; case 'Adzone': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $servername = DB_HOST . ":" . DB_PORT; $username = DB_USERNAME; $password = DB_PASSWORD; $dbname = DB_NAME; $cacheKey = 'Adzone'; $arrAdzone = $redis->hgetall($cacheKey); $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = ''; foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $publisher_site_id = $data['publisher_site_id']; $sql = <<<EOF SELECT url FROM pt_publisher_site WHERE id = {$publisher_site_id} EOF; $result = $conn->query($sql); $arrTmp = array(); if ($result->num_rows > 0) { $arrTmp = $result->fetch_assoc(); } $data['site'] = $arrTmp; $publisher_ad_zone_id = $data['id']; $sql = <<<EOF SELECT code, weight FROM pt_publisher_alternate_ad WHERE publisher_ad_zone_id = {$publisher_ad_zone_id} EOF; $result = $conn->query($sql); $arrTmp = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $arrTmp[] = $row; } } $data['alternateAds'] = $arrTmp; $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrAdzone[$data['id']]); } } if (!empty($arrAdzone)) { foreach ($arrAdzone as $id => $zone) { $redis->hdel($cacheKey, $id); } } break; case 'Ad': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'Ad'; $arrAd = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrAd[$data['id']]); } } if (!empty($arrAd)) { foreach ($arrAd as $id => $ad) { $redis->hdel($cacheKey, $id); } } break; case 'PublisherAlternateAd': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_2); $cacheKey = 'PublisherAlternateAd'; $arrPublisherAlternateAd = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $redis->hset($cacheKey, $data['publisher_ad_zone_id'], json_encode($data)); unset($arrPublisherAlternateAd[$data['publisher_ad_zone_id']]); } } if (!empty($arrPublisherAlternateAd)) { foreach ($arrPublisherAlternateAd as $id => $publisherAlternateAd) { $redis->hdel($cacheKey, $id); } } break; case 'FlightDate': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'FlightDate'; $arrFlightDate = $redis->hgetall($cacheKey); $arrFlight = array(); foreach ($arrData as $data) { if (!empty($data)) { $data['hour'] = json_decode($data['hour']); $arrFlight[$data['flight_id']][] = $data; } } foreach ($arrFlight as $key => $flight) { $redis->hset($cacheKey, $key, json_encode($flight)); //print_r($flight); unset($arrFlightDate[$key]); } if (!empty($arrFlightDate)) { foreach ($arrFlightDate as $id => $flightDate) { $redis->hdel($cacheKey, $id); } } break; case 'PublisherSite': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'PublisherSite'; $arrPublisherSite = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrPublisherSite[$data['id']]); } } if (!empty($arrPublisherSite)) { foreach ($arrPublisherSite as $id => $publisherSite) { $redis->hdel($cacheKey, $id); } } break; case 'PublisherAdZone': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'PublisherAdZone'; $arrPublisherAdZone = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrPublisherAdZone[$data['id']]); } } if (!empty($arrPublisherAdZone)) { foreach ($arrPublisherAdZone as $id => $publisherAdZone) { $redis->hdel($cacheKey, $id); } } break; case 'Category': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'Category'; $arrCategory = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrCategory[$data['id']]); } } if (!empty($arrCategory)) { foreach ($arrCategory as $id => $category) { $redis->hdel($cacheKey, $id); } } break; case 'AdFormat': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'Ad_Format'; $arrAdFormat = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrAdFormat[$data['id']]); } } if (!empty($arrAdFormat)) { foreach ($arrAdFormat as $id => $adFormat) { $redis->hdel($cacheKey, $id); } } break; case 'FlightWebsite': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $arrFlightWebsite = array(); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $cacheKey = "FlightWebsite_{$data['website_id']}_{$data['ad_format_id']}"; if (empty($arrFlightWebsite[$cacheKey])) { $arrFlightWebsite[$cacheKey] = $redis->hgetall($cacheKey); } $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrFlightWebsite[$cacheKey][$data['id']]); } } foreach ($arrFlightWebsite as $key => $flightWebsite) { foreach ($flightWebsite as $id => $fw) { $redis->hdel($key, $id); } } break; case 'Conversion': $redis = new Redis(); $redis->connect(REDIS_HOST, REDIS_PORT_1); $cacheKey = 'Conversion'; $arrConversion = $redis->hgetall($cacheKey); foreach ($arrData as $data) { if (!empty($data)) { //print_r($data); $data['param'] = json_decode($data['param']); $redis->hset($cacheKey, $data['id'], json_encode($data)); unset($arrConversion[$data['id']]); } } if (!empty($arrConversion)) { foreach ($arrConversion as $id => $conversion) { $redis->hdel($cacheKey, $id); } } break; } }
/** * Increment a raw value * * @param string $id Cache ID * @param int $offset Step/value to add * @return mixed New value on success or FALSE on failure */ public function hset($alias, $key, $value) { return $this->_redis->hset($alias, $key, $value); }
$data = $redis->sort("myset", array("sort" => "desc")); echo "<pre>"; print_r($data); for ($i = 0; $i < 10; $i++) { $redis->zadd("zset", $i + rand(10, 99), $i + rand(100, 999)); } $data = $redis->zrange("zset", 0, 3, "withscores"); echo "<pre>"; print_r($data); $redis->zrem("zset", 456); echo $redis->zcount("zset", 10, 50); $redis->zRemRangeByScore("key", star, end); echo $redis->zScore("zset", 503); echo $redis->zrank("zset", 723); for ($i = 0; $i < 10; $i++) { $redis->hset("myhash", $i, rand(10, 99) + $i); } echo $redis->hget("myhash", "0"); echo $redis->hlen("myhash"); echo $redis->hdel("myhash", "0"); $data = $redis->hkeys("myhash"); $data = $redis->hvals("myhash"); $data = $redis->hgetall("myhash"); echo "<pre>"; print_r($data); echo $redis->hexists("myhash", "0"); $redis->hmset("user:1", array("name1" => "name1", "name2" => "Joe2")); $data = $redis->hmget("user:1", array('name', 'salary')); print_r($data); // redis $redis->move("key1", 2);
$arr_num[$k] = count($v); $cont[] = count($v) . ',' . $k . ',' . $v[$i][1] . ',' . $date; } } //print_r($cont);die; for ($i = 0; $i < count($cont); $i++) { $cont_arr[] = explode(",", $cont[$i]); } //print_r($cont_arr);die; $redis = new Redis(); $redis->connect('127.0.0.1', 6379); foreach ($cont_arr as $key => $val) { $vals[] = $redis->hget("server", $val[2]); if ($vals) { $redis->hdel("server", $val[2]); $redis->hset("server", $val[2], json_encode($val)); } else { $redis->hset("server", $val[2], json_encode($val)); } } //print_r($redis->hGetAll("server"));die; /* * Mbr 日 启 动 统 计 */ //信息分割成数组 for ($i = 0; $i < count($install); $i++) { $info_arr[] = explode(",", $install[$i]); } //print_r($info_arr);die; //选出Mbr启动的记录 foreach ($info_arr as $a => $b) {
public function testHashes() { $this->redis->delete('h', 'key'); $this->assertTrue(0 === $this->redis->hLen('h')); $this->assertTrue(TRUE === $this->redis->hSet('h', 'a', 'a-value')); $this->assertTrue(1 === $this->redis->hLen('h')); $this->assertTrue(TRUE === $this->redis->hSet('h', 'b', 'b-value')); $this->assertTrue(2 === $this->redis->hLen('h')); $this->assertTrue('a-value' === $this->redis->hGet('h', 'a')); // simple get $this->assertTrue('b-value' === $this->redis->hGet('h', 'b')); // simple get $this->assertTrue(FALSE === $this->redis->hSet('h', 'a', 'another-value')); // replacement $this->assertTrue('another-value' === $this->redis->hGet('h', 'a')); // get the new value $this->assertTrue('b-value' === $this->redis->hGet('h', 'b')); // simple get $this->assertTrue(FALSE === $this->redis->hGet('h', 'c')); // unknown hash member $this->assertTrue(FALSE === $this->redis->hGet('key', 'c')); // unknownkey // hDel $this->assertTrue(TRUE === $this->redis->hDel('h', 'a')); // TRUE on success $this->assertTrue(FALSE === $this->redis->hDel('h', 'a')); // FALSE on failure $this->redis->delete('h'); $this->redis->hSet('h', 'x', 'a'); $this->redis->hSet('h', 'y', 'b'); // keys $keys = $this->redis->hKeys('h'); $this->assertTrue($keys === array('x', 'y') || $keys === array('y', 'x')); // values $values = $this->redis->hVals('h'); $this->assertTrue($values === array('a', 'b') || $values === array('b', 'a')); // keys + values $all = $this->redis->hGetAll('h'); $this->assertTrue($all === array('x' => 'a', 'y' => 'b') || $all === array('y' => 'b', 'x' => 'a')); // hExists $this->assertTrue(TRUE === $this->redis->hExists('h', 'x')); $this->assertTrue(TRUE === $this->redis->hExists('h', 'y')); $this->assertTrue(FALSE === $this->redis->hExists('h', 'w')); $this->redis->delete('h'); $this->assertTrue(FALSE === $this->redis->hExists('h', 'x')); // hIncrBy $this->redis->delete('h'); $this->assertTrue(25 === $this->redis->hIncrBy('h', 'x', 25)); $this->assertTrue(35 === $this->redis->hIncrBy('h', 'x', 10)); $this->redis->hSet('h', 'y', 'not-a-number'); $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 'y', 1)); $this->redis->delete('h1'); //hMGet, hMSet $this->redis->hset("h1", "field1", "value1"); $this->redis->hset("h1", "field2", "value2"); $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2') === $this->redis->hGetAll('h1')); $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2') === $this->redis->hMGet('h1', array('field1', 'field2'))); $this->assertTrue(array('field1' => 'value1') === $this->redis->hMGet('h1', array('field1'))); $this->assertTrue(FALSE === $this->redis->hMGet('h1', array())); $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('field3' => 'value3'))); $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2', 'field3' => 'value3') === $this->redis->hGetAll('h1')); $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('field3' => 'value4'))); $this->assertTrue(array('field1' => 'value1', 'field2' => 'value2', 'field3' => 'value4') === $this->redis->hGetAll('h1')); $this->assertTrue(TRUE === $this->redis->hMSet('h1', array('x' => 0, 'y' => array(), 'z' => new stdclass()))); $h1 = $this->redis->hGetAll('h1'); $this->assertTrue('0' === $h1['x']); $this->assertTrue('Array' === $h1['y']); $this->assertTrue('Object' === $h1['z']); }
public function hset($collect, $key, $value, $issame = false) { $result = parent::hset($collect, $key, $value); if ($issame) { return $result; } if ($result == 0 || $result == 1) { return true; } return false; }
<?php /** */ if (array_key_exists("k", $_GET) && array_key_exists("v", $_GET) && array_key_exists("st", $_GET)) { $redis = new Redis(); $redis->pconnect('127.0.0.1'); $res = $redis->hset($_GET['st'], $_GET['k'], $_GET['v']); echo $res; } else { echo 'params error'; }
public function hset($key, $hash, $value, $serialize = true) { $value = $serialize ? serialize($value) : $value; return $this->handler->hset($key, $hash, $value); }
/** * @inheritdoc */ public function log($id, $originalId, array $context) { $this->redis->hset($id, $originalId, json_encode($context)); }
} else { if ($msg['type'] == 'popo') { $redis = new Redis(); $redis->connect('localhost', 6379); $popid = $redis->incr('popoid'); $msg['id'] = 'p' . $popid; $client = new RouterClient('127.0.0.1', 9010); $client->sendAllMsg(json_encode($msg)); } else { if ($msg['type'] == 'boom') { $client = new RouterClient('127.0.0.1', 9010); $client->sendAllMsg($data); } else { if ($msg['type'] == 'message') { //$msg['text'] = mb_substr($msg['text'], 0, 10); $client = new RouterClient('127.0.0.1', 9010); $client->sendAllMsg($data); } else { if ($msg['type'] == 'kill') { $redis = new Redis(); $key = 'role:' . $msg['id']; $redis->connect('localhost', 6379); $redis->hset($key, 'die', 1); } } } } } } } }
if ($redis->exists($keyname)) { $status = $redis->hget($keyname, 'status'); $cookieexist = $redis->hget($keyname, 'cookie'); if ($status == 'processing') { echo "<script>alert('正在为你领取银瓜子~');history.go(-1);</script>"; exit; } elseif ($status == 'processed') { echo "<script>alert('今天的银瓜子已经领完了,明天再来吧~');history.go(-1);</script>"; exit; } elseif ($status == 'problem') { if ($cookieexist == $cookie) { echo "<script>alert('Cookie数据有问题,请尝试重新登录获取后再提交!');history.go(-1);</script>"; exit; } else { echo "<script>alert('成功更新Cookie数据!');</script>"; } } else { echo "<script>alert('你的任务正在队列中,稍后再看看吧~');history.go(-1);</script>"; exit; } } $outtime = strtotime("tomorrow") - time(); if ($outtime <= 3600) { echo "<script>alert('今天太晚了,明天再来吧~');history.go(-1);</script>"; exit; } $redis->hset($keyname, 'cookie', $cookie); $redis->hset($keyname, 'status', 'queuing'); $redis->expire($keyname, $outtime); echo "<script>alert('你的任务已经加入队列中,下一个小时开始领取!');history.go(-1);</script>"; exit;
/** * Set job property * * @param string $key * @param string $val * @return $this */ public function set($key, $val) { $this->injectors[$key] = $val; $this->client->hset('q:job:' . $this->injectors['id'], $key, $val); return $this; }