public function it_can_hget() { $this->redis->hGet('test', 'test')->shouldBeCalled()->willReturn('test'); $this->hGet('test', 'test')->shouldReturn('test'); $this->redis->hGet('test', 'test')->willThrow(new \RedisException()); $this->shouldThrow(DriverException::class)->during('hGet', ['test', 'test']); }
/** * 根据 category_id 获取顶级分类的信息 * @param $categoriesId * @return array */ public function getParentById($categoriesId) { if ($this->redis->hLen($this->redisParentChildKey) == 0) { $this->setRedisCategoryParentChild(); } $parentId = $this->redis->hGet($this->redisParentChildKey, $categoriesId); return ['categories_id' => $parentId, 'categories_name' => $this->getCategoryNameById($parentId)]; }
/** * get var * * @param $key * @param null $default * @return bool|string|null */ public function get($key, $default = null) { $result = $this->redis->hGet($this->prefix, $key); if ($result !== false) { return $result; } return $default; }
public static function settings($app) { $html = new simple_html_dom(); $html->load_file($app->rootUri . "/settings"); $selects = $html->find('select'); $inputs = $html->find('input'); $boxes = $html->find('#features-management', 0); // connect to the database $redis = new \Redis(); $redis->pconnect('127.0.0.1'); $obj = array("settings" => array("environment" => array("hostname" => $redis->get('hostname'), "ntp_server" => $redis->get('ntpserver'), "timezone" => $redis->get('timezone')), "kernel" => array("i2s_modules" => $redis->get('i2smodule')), "features" => array("airplay" => $redis->hGet('airplay', 'enable'), "airplay_name" => $redis->hGet('airplay', 'name'), "spotify" => $redis->hGet('spotify', 'enable'), "spotify_username" => $redis->hGet('spotify', 'user'), "spotify_password" => $redis->hGet('spotify', 'pass'), "upnp_dlna" => $redis->hGet('dlna', 'enable'), "upnp_dlna_name" => $redis->hGet('dlna', 'name'), "usb_automount" => $redis->get('udevil'), "coverart" => $redis->get('coverart'), "lastfm" => $redis->hGet('lastfm', 'enable'), "lastfm_username" => $redis->hGet('lastfm', 'user'), "lastfm_password" => $redis->hGet('lastfm', 'pass')), "compatibility_fix" => array("cmedia_fix" => "unknown"))); echo json_encode($obj); }
/** * Get entry from cache storage * * @param string $key * * @return mixed */ public function get($key) { $entry = $this->redis->hGet($this->cacheKey, $key); if ($entry) { $entry = unserialize($entry); if ($entry['expire']) { // Check expires $now = new \DateTime('now', new \DateTimeZone('UTC')); if ((int) $now->format('U') > $entry['expire']) { $this->remove($key); return null; } } return $entry['value']; } return null; }
/** * @param string $messageId * @return Message */ protected function getMessageById($messageId) { if (!is_string($messageId)) { return null; } $encodedPayload = $this->client->hGet("queue:{$this->name}:ids", $messageId); $numberOfReleases = (int) $this->client->hGet("queue:{$this->name}:releases", $messageId); return new Message($messageId, json_decode($encodedPayload, true), $numberOfReleases); }
/** * hGet cache * * @param string Cache ID * @return mixed */ public function hget($key, $hashkey) { $value = $this->_redis->hGet($key, $hashkey); if ($value !== FALSE && isset($this->_serialized[$key])) { //die($value); return unserialize(base64_decode($value)); } return $value; }
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(2.5 === $this->redis->hIncrBy('h', 2.5, 'x')); $this->assertTrue(3.5 === $this->redis->hIncrBy('h', 1, 'x')); $this->redis->hSet('h', 'y', 'not-a-number'); $this->assertTrue(FALSE === $this->redis->hIncrBy('h', 1, 'y')); */ }
/** * Execute the job. * * @return void */ public function handle() { // 避免重复操作 if ($this->attempts() > 3) { return; } $this->redis = PRedis::connection(); if (is_object($this->sheet)) { $vote_dest = 'jk_upvote:' . $this->sheet->getAttributeValue('song_id') . ':userLIST'; if (true == $this->redis->hGet($vote_dest, $this->user)) { return; } $this->redis->hSet($vote_dest, $this->user, 1); $vote_count = $this->redis->hLen($vote_dest); $stat = $this->sheet->storeUpVoteNumber($this->sheet->getAttributeValue('song_id'), $vote_count); if (!$stat) { $this->failed(); } } }
/** * @param string $key * @param string $hashKey * @param UnserializesDataToString $unserializer * * @return bool|string */ public function getHashValueAsUnserializedString($key, $hashKey, UnserializesDataToString $unserializer) { $serializer = $this->redis->getOption(\Redis::OPT_SERIALIZER); $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE); $value = $this->redis->hGet($key, $hashKey); if ($value !== false) { $unserializedValue = $unserializer->unserialize($value); } else { $unserializedValue = false; } $this->redis->setOption(\Redis::OPT_SERIALIZER, $serializer); return $unserializedValue; }
private function requeueOldWorkingMessages($type) { $messageIds = array_unique($this->redis->lRange($this->getMessageRunKey($type), 0, -1)); foreach ($messageIds as $messageId) { $time = $this->redis->hGet($this->getMessageStartTimeKey($type), $messageId); if (!empty($time) && time() > $this->messageTimeout + (int) $time) { $this->redis->multi(); $this->redis->rPush($this->getMessageQueueKey($type), $messageId); $this->redis->lRem($this->getMessageRunKey($type), $messageId, 1); $this->redis->hDel($this->getMessageStartTimeKey($type), $messageId); $this->redis->exec(); } } }
/** * 获取周期任务的ID列表 * * @param string|null $tubeName * @return array */ public function getPeriodic($tubeName = null) { $container = array(); $ret = $this->getDelayed($tubeName); if (is_array($ret)) { foreach ($ret as $jobId) { $periodic = $this->client->hGet($this->name . ':' . Job::JOB_TAB . ':' . $jobId, 'periodic'); if ($periodic > 0) { $container[] = $jobId; } } } return $container; }
/** * 获取一个任务 * * @return bool|Caster */ private function getReadyJob() { $keyChip = $this->queue->name . ':' . Job::JOBS_TAB . ':' . $this->tube . ':'; $timePort = Util::now(); $this->expireActivate($keyChip, $timePort); if (!($id = $this->pop($keyChip . Job::STATE_READY, $timePort))) { return false; } if (!($job = Caster::reload($id))) { return false; } $this->client->hIncrBy($this->queue->name . ':' . Job::JOB_TAB . ':' . $id, 'retry_times', 1); $this->jobId = $id; $this->periodic = $this->client->hGet($this->queue->name . ':' . Job::JOB_TAB . ':' . $id, 'periodic'); return $job; }
public function getResult($taskId) { $serializedTaskResult = $this->redis->hGet($this->getTaskResultKey(), $taskId); if (empty($serializedTaskResult)) { return null; } do { $resultReady = $this->redis->blPop($this->getTaskResultReadyKey($taskId), 1); } while (empty($resultReady)); $serializedTaskResult = $this->redis->hGet($this->getTaskResultKey(), $taskId); $taskResult = unserialize($serializedTaskResult); $this->redis->hDel($this->getTaskResultKey(), $taskId); if ($taskResult instanceof TaskException) { throw $taskResult; } return $taskResult; }
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 hGet($key, $field) { return $this->connection->hGet($key, $field); }
/** * 获取hash表的数据 * @param $hash string 哈希表名 * @param $key mixed 表中要存储的key名 默认为null 返回所有key->value * @param $type int 要获取的数据类型 0:返回所有key 1:返回所有value 2:返回所有key->value */ public static function hashGet($hash, $key = array(), $type = 0) { $redis = new \Redis(); $redis->connect(self::_HOST, self::_PORT); $return = null; if ($key) { if (is_array($key) && !empty($key)) { $return = $redis->hMGet($hash, $key); } else { $return = $redis->hGet($hash, $key); } } else { switch ($type) { case 0: $return = $redis->hKeys($hash); break; case 1: $return = $redis->hVals($hash); break; case 2: $return = $redis->hGetAll($hash); break; default: $return = false; break; } } $redis->close(); $redis = null; return $return; }
$libs = APP . 'libs/vendor'; set_include_path(get_include_path() . PATH_SEPARATOR . $libs); // RuneAudio Library include include APP . 'libs/runeaudio.php'; // Connect to Redis backend $redis = new Redis(); $redis->pconnect('127.0.0.1'); //$redis->pconnect('/tmp/redis.sock'); $devmode = $redis->get('dev'); $activePlayer = $redis->get('activePlayer'); // LogSettings if ($redis->get('debug') > 0) { $activeLog = 1; } else { $activeLog = 0; } ini_set('log_errors', $activeLog); ini_set('error_log', '/var/log/runeaudio/runeui.log'); ini_set('display_errors', $activeLog); // connect to MPD daemon if ($_SERVER["SCRIPT_FILENAME"] === '/var/www/command/index.php' && $activePlayer === 'MPD') { // debug runelog('[connection.php] >>> OPEN MPD SOCKET [NORMAL MODE [0] (blocking)] <<<', ''); $mpd = openMpdSocket('/run/mpd.sock', 0); } elseif ($activePlayer === 'MPD') { // debug runelog('[connection.php] >>> OPEN MPD SOCKET [BURST MODE [1] (blocking)] <<<', ''); $mpd = openMpdSocket('/run/mpd.sock', 1); } elseif ($redis->hGet('spotify', 'enable') === '1' && $activePlayer === 'Spotify') { $spop = openSpopSocket('localhost', 6602, 1); }
/** * 获取任务属性 * * @param string $key * @return mixed */ protected function get($key) { return $this->client->hGet($this->queue->name . ':' . self::JOB_TAB . ':' . $this->injectors['id'], $key); }
<?php if ($_POST && isset($_POST['location'], $_POST['service'], $_POST['check'], $_POST['value'])) { $redis_server = 'localhost:6379'; try { $redis = new Redis(); $redis->connect($redis_server); $location = $_POST['location']; $service = $_POST['service']; $check = $_POST['check']; $value = $_POST['value']; $date = new DateTime(); $timestamp = $date->getTimestamp(); $redis->hSet('locations', $location, $timestamp); $redis->hSet('services', $service, $timestamp); $redis->hSet('checks', $check, $timestamp); if ($redis->hExists($location . ':' . $service, $check)) { $prev_value = $redis->hGet($location . ':' . $service, $check); } else { $prev_value = ""; } $redis->hSet($location . ':' . $service, $check, $value); if (strcmp($prev_value, "RUN") != 0) { $redis->hSet($location . ':' . $service, $check . ':prev', $prev_value); } $redis->hSet($location . ':' . $service, $check . ':time', $timestamp); } catch (RedisException $e) { die($e->getMessage()); } }
/** * @param string $key * @param string $member * @return string|FALSE */ public function hGet($key, $member) { return parent::hGet($key, $member); }
private function checkSerializer($mode) { $this->redis->delete('key'); $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE); // default $this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, $mode) === TRUE); // set ok $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === $mode); // get ok // lPush, rPush $a = array('hello world', 42, TRUE, array('<tag>' => 1729)); $this->redis->delete('key'); $this->redis->lPush('key', $a[0]); $this->redis->rPush('key', $a[1]); $this->redis->rPush('key', $a[2]); $this->redis->rPush('key', $a[3]); // lGetRange $this->assertTrue($a === $this->redis->lGetRange('key', 0, -1)); // lGet $this->assertTrue($a[0] === $this->redis->lGet('key', 0)); $this->assertTrue($a[1] === $this->redis->lGet('key', 1)); $this->assertTrue($a[2] === $this->redis->lGet('key', 2)); $this->assertTrue($a[3] === $this->redis->lGet('key', 3)); // lRemove $this->assertTrue($this->redis->lRemove('key', $a[3]) === 1); $this->assertTrue(array_slice($a, 0, 3) === $this->redis->lGetRange('key', 0, -1)); // lSet $a[0] = array('k' => 'v'); // update $this->assertTrue(TRUE === $this->redis->lSet('key', 0, $a[0])); $this->assertTrue($a[0] === $this->redis->lGet('key', 0)); // lInsert $this->assertTrue($this->redis->lInsert('key', Redis::BEFORE, $a[0], array(1, 2, 3)) === 4); $this->assertTrue($this->redis->lInsert('key', Redis::AFTER, $a[0], array(4, 5, 6)) === 5); $a = array(array(1, 2, 3), $a[0], array(4, 5, 6), $a[1], $a[2]); $this->assertTrue($a === $this->redis->lGetRange('key', 0, -1)); // sAdd $this->redis->delete('key'); $s = array(1, 'a', array(1, 2, 3), array('k' => 'v')); $this->assertTrue(1 === $this->redis->sAdd('key', $s[0])); $this->assertTrue(1 === $this->redis->sAdd('key', $s[1])); $this->assertTrue(1 === $this->redis->sAdd('key', $s[2])); $this->assertTrue(1 === $this->redis->sAdd('key', $s[3])); // variadic sAdd $this->redis->delete('k'); $this->assertTrue(3 === $this->redis->sAdd('k', 'a', 'b', 'c')); $this->assertTrue(1 === $this->redis->sAdd('k', 'a', 'b', 'c', 'd')); // sRemove $this->assertTrue(1 === $this->redis->sRemove('key', $s[3])); $this->assertTrue(0 === $this->redis->sRemove('key', $s[3])); // variadic $this->redis->delete('k'); $this->redis->sAdd('k', 'a', 'b', 'c', 'd'); $this->assertTrue(2 === $this->redis->sRem('k', 'a', 'd')); $this->assertTrue(2 === $this->redis->sRem('k', 'b', 'c', 'e')); $this->assertTrue(FALSE === $this->redis->exists('k')); // sContains $this->assertTrue(TRUE === $this->redis->sContains('key', $s[0])); $this->assertTrue(TRUE === $this->redis->sContains('key', $s[1])); $this->assertTrue(TRUE === $this->redis->sContains('key', $s[2])); $this->assertTrue(FALSE === $this->redis->sContains('key', $s[3])); unset($s[3]); // sMove $this->redis->delete('tmp'); $this->redis->sMove('key', 'tmp', $s[0]); $this->assertTrue(FALSE === $this->redis->sContains('key', $s[0])); $this->assertTrue(TRUE === $this->redis->sContains('tmp', $s[0])); unset($s[0]); // sorted sets $z = array('z0', array('k' => 'v'), FALSE, NULL); $this->redis->delete('key'); // zAdd $this->assertTrue(1 === $this->redis->zAdd('key', 0, $z[0])); $this->assertTrue(1 === $this->redis->zAdd('key', 1, $z[1])); $this->assertTrue(1 === $this->redis->zAdd('key', 2, $z[2])); $this->assertTrue(1 === $this->redis->zAdd('key', 3, $z[3])); // zDelete $this->assertTrue(1 === $this->redis->zDelete('key', $z[3])); $this->assertTrue(0 === $this->redis->zDelete('key', $z[3])); unset($z[3]); // check that zDelete doesn't crash with a missing parameter (GitHub issue #102): $this->assertTrue(FALSE === @$this->redis->zDelete('key')); // variadic $this->redis->delete('k'); $this->redis->zAdd('k', 0, 'a'); $this->redis->zAdd('k', 1, 'b'); $this->redis->zAdd('k', 2, 'c'); $this->assertTrue(2 === $this->redis->zDelete('k', 'a', 'c')); $this->assertTrue(1.0 === $this->redis->zScore('k', 'b')); $this->assertTrue($this->redis->zRange('k', 0, -1, true) == array('b' => 1.0)); // zRange $this->assertTrue($z === $this->redis->zRange('key', 0, -1)); // zScore $this->assertTrue(0.0 === $this->redis->zScore('key', $z[0])); $this->assertTrue(1.0 === $this->redis->zScore('key', $z[1])); $this->assertTrue(2.0 === $this->redis->zScore('key', $z[2])); // zRank $this->assertTrue(0 === $this->redis->zRank('key', $z[0])); $this->assertTrue(1 === $this->redis->zRank('key', $z[1])); $this->assertTrue(2 === $this->redis->zRank('key', $z[2])); // zRevRank $this->assertTrue(2 === $this->redis->zRevRank('key', $z[0])); $this->assertTrue(1 === $this->redis->zRevRank('key', $z[1])); $this->assertTrue(0 === $this->redis->zRevRank('key', $z[2])); // zIncrBy $this->assertTrue(3.0 === $this->redis->zIncrBy('key', 1.0, $z[2])); $this->assertTrue(3.0 === $this->redis->zScore('key', $z[2])); $this->assertTrue(5.0 === $this->redis->zIncrBy('key', 2.0, $z[2])); $this->assertTrue(5.0 === $this->redis->zScore('key', $z[2])); $this->assertTrue(2.0 === $this->redis->zIncrBy('key', -3.0, $z[2])); $this->assertTrue(2.0 === $this->redis->zScore('key', $z[2])); // mset $a = array('k0' => 1, 'k1' => 42, 'k2' => NULL, 'k3' => FALSE, 'k4' => array('a' => 'b')); $this->assertTrue(TRUE === $this->redis->mset($a)); foreach ($a as $k => $v) { $this->assertTrue($this->redis->get($k) === $v); } $a = array('k0' => 1, 'k1' => 42, 'k2' => NULL, 'k3' => FALSE, 'k4' => array('a' => 'b')); // hSet $this->redis->delete('key'); foreach ($a as $k => $v) { $this->assertTrue(1 === $this->redis->hSet('key', $k, $v)); } // hGet foreach ($a as $k => $v) { $this->assertTrue($v === $this->redis->hGet('key', $k)); } // hGetAll $this->assertTrue($a === $this->redis->hGetAll('key')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k0')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k1')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k2')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k3')); $this->assertTrue(TRUE === $this->redis->hExists('key', 'k4')); // hMSet $this->redis->delete('key'); $this->redis->hMSet('key', $a); foreach ($a as $k => $v) { $this->assertTrue($v === $this->redis->hGet('key', $k)); } // hMget $hmget = $this->redis->hMget('key', array_keys($a)); foreach ($hmget as $k => $v) { $this->assertTrue($v === $a[$k]); } // getMultiple $this->redis->set('a', NULL); $this->redis->set('b', FALSE); $this->redis->set('c', 42); $this->redis->set('d', array('x' => 'y')); $this->assertTrue(array(NULL, FALSE, 42, array('x' => 'y')) === $this->redis->getMultiple(array('a', 'b', 'c', 'd'))); // pipeline $this->sequence(Redis::PIPELINE); // multi-exec $this->sequence(Redis::MULTI); // keys $this->assertTrue(is_array($this->redis->keys('*'))); // issue #62, hgetall $this->redis->del('hash1'); $this->redis->hSet('hash1', 'data', 'test 1'); $this->redis->hSet('hash1', 'session_id', 'test 2'); $data = $this->redis->hGetAll('hash1'); $this->assertTrue($data['data'] === 'test 1'); $this->assertTrue($data['session_id'] === 'test 2'); // issue #145, serializer with objects. $this->redis->set('x', array(new stdClass(), new stdClass())); $x = $this->redis->get('x'); $this->assertTrue(is_array($x)); $this->assertTrue(is_object($x[0]) && get_class($x[0]) === 'stdClass'); $this->assertTrue(is_object($x[1]) && get_class($x[1]) === 'stdClass'); // revert $this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE) === TRUE); // set ok $this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE); // get ok }
/** * Get the value associated with a given key. * * @param string $key The key to get the value of. * @return mixed The value of the key, or false if there is no value associated with the key. */ public function get($key) { return $this->redis->hGet($this->hash, $key); }
<?php require_once __DIR__ . '/../Bancard/autoload.php'; $redis = new Redis(); $redis->pconnect('127.0.0.1', 6379); $id = !empty($_GET['id']) ? $_GET['id'] : 0; if (!$id) { die("Invalid parameters."); } $pid = $redis->hGet("LlevaUno:Bancard:PreAuthorization:PreAuthorization:" . $id, "shop_process_id"); if (!$pid) { die("No pid was selected."); } $data = ['shop_process_id' => $pid]; try { $request = LlevaUno\Bancard\Operations\PreAuthorization\Cancel::init($data)->send(); } catch (Exception $e) { die($e->getMessage()); } $redis->hSet("LlevaUno:Bancard:PreAuthorization:Cancel:{$id}", "shop_process_id", "{$id}"); $redis->hSet("LlevaUno:Bancard:PreAuthorization:Cancel:{$id}", "data", json_encode($data)); $redis->hSet("LlevaUno:Bancard:PreAuthorization:Cancel:{$id}", "request", $request->json()); $redis->hSet("LlevaUno:Bancard:PreAuthorization:Cancel:{$id}", "response", json_encode($request->response));
<?php require_once dirname(__FILE__) . "/../title.php"; require_once dirname(__FILE__) . "/../util.php"; if (!$_GET["redis_ip"]) { echo "没有输入redis ip"; return; } if (!$_GET["redis_port"]) { echo "没有输入redis端口"; return; } if (!$_GET["player_uin"]) { echo "没有输入玩家uin"; return; } $redis_ip = $_GET["redis_ip"]; $redis_port = $_GET["redis_port"]; $player_uin = $_GET["player_uin"]; $redis = new Redis(); if ($redis->connect($redis_ip, $redis_port, 10) == false) { echo "redis 连接失败"; } else { $result = $redis->hGet("account", $player_uin); if ($result) { echo $result; } else { echo "玩家不存"; } }
foreach ($locations as $location) { $tbl .= "<th>" . $location . "</th>"; } $tbl .= "</tr>"; $date = new DateTime(); $timestamp = $date->getTimestamp(); $rowscount = count($checks); foreach ($services as $service) { $nonexist_locations = array(); $service_row = "<tr><td rowspan=%d style='border-top-style: solid;'>" . $service . "</td>"; $opentag = 0; $closetag = 1; foreach ($checks as $check) { $add_check = 1; foreach ($locations as $location) { $value = $redis->hGet($location . ':' . $service, $check); $prev_value = $redis->hGet($location . ':' . $service, $check . ':prev'); $is_supported = False; if ($redis->hExists($location . ':' . $service, $check . ':time')) { if ($add_check == 1 && $opentag == 1) { $service_row .= "<tr>"; $add_check = 0; $closetag = 1; } $time = $redis->hGet($location . ':' . $service, $check . ':time'); if ($timestamp - $time < 60) { $is_supported = True; } else { $is_supported = False; } $service_row = choose_cell_color($service_row, $check, $value, $prev_value, $opentag, $is_supported);
try { $redis->connect($redis_host, $redis_port); } catch (RedisException $e) { $return = array(); $return['error'] = 'Could not connect to the redis host'; $return['action'] = 'none'; echo json_encode($return); exit; } // Set the name of the key for the lock $keyName = "schedule:{$employee}:{$period}"; // Set the ttl on the lock $lockDuration = 600; // Check to see if a lock is in place // NOTE: $curLockedBy = false if the key does not exist $curLockedBy = $redis->hGet($keyName, 'lockedBy'); // Construct the return object $return = array('status' => '', 'action' => '', 'lockedBy' => '', 'ttl' => ''); // If a lock was requested if ($lock) { // If lock is already held, or not held if ($curLockedBy == $lockedBy || !$curLockedBy) { // Set the lock and set the expire timout $redis->hSet($keyName, 'lockedBy', $lockedBy); $redis->expire($keyName, $lockDuration); $return['status'] = 'locked'; // If the lock is renewed, then set to renewed, otherwise set to locked $return['action'] = $curLockedBy == $lockedBy ? 'renewed' : 'locked'; $return['lockedBy'] = $lockedBy; $return['ttl'] = 600; } else {