Exemplo n.º 1
0
 /**
  * 获取订单数据
  * @return mixed
  */
 public function setRedisCategoryDescription()
 {
     // TODO: Implement setRedisOrderSn() method.
     $epathDb = Yii::$app->epathDb;
     $query = (new Query())->select('categories_id,categories_name')->from('categories_description')->where("1");
     $categoryDescriptionList = $query->all($epathDb);
     foreach ($categoryDescriptionList as $categoryDescription) {
         $this->redis->hSet($this->redisDescriptionKey, $categoryDescription['categories_id'], $categoryDescription['categories_name']);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl) {
         $now = new \DateTime('now', new \DateTimeZone('UTC'));
         $expire = (int) $now->format('U') + $ttl;
     } else {
         $expire = 0;
     }
     $entry = array('expire' => $expire, 'value' => $value);
     $this->redis->hSet($this->cacheKey, $key, serialize($entry));
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function gauge($bucket, $value)
 {
     $time = $this->syncedTime();
     $granularities = $this->getGranularities();
     foreach ($granularities as $granularity => $settings) {
         $key = $this->getKey($bucket, 'gauges', $granularity, $settings, $time);
         $field = $this->getField($settings, $time);
         $this->redis->hSet($key, $field, $value);
         $this->redis->expireAt($key, $time + $settings['ttl']);
     }
     $this->redis->sAdd('buckets', $bucket);
     $this->redis->sAdd(sprintf('types:%s', $bucket), 'gauges');
 }
Exemplo n.º 4
0
 /**
  * @inheritdoc
  */
 public function release($messageId, array $options = [])
 {
     $this->checkClientConnection();
     $this->client->lRem("queue:{$this->name}:processing", $messageId, 0);
     $numberOfReleases = (int) $this->client->hGet("queue:{$this->name}:releases", $messageId);
     $this->client->hSet("queue:{$this->name}:releases", $messageId, $numberOfReleases + 1);
     $this->client->lPush("queue:{$this->name}:messages", $messageId);
 }
Exemplo n.º 5
0
 protected function setCached(Bookmark $bookmark, $redisKey)
 {
     if ($this->redis !== null) {
         $this->redis->hSet($redisKey, $bookmark->url, 1);
         if ($this->redis->ttl($redisKey) < 0) {
             $this->redis->expire($redisKey, 4 * 7 * 24 * 60 * 60);
         }
     }
 }
Exemplo n.º 6
0
 public function testPerfDirectRedis()
 {
     $redis = new Redis();
     $redis->connect(self::$REDIS_HOST, self::$REDIS_PORT);
     $cb = $this->getProfilerForCallback(function ($e) use($redis) {
         $redis->hSet($e, 'data', '');
     });
     $cb(self::TEST_TIME, __METHOD__);
 }
Exemplo n.º 7
0
 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'));
     */
 }
Exemplo n.º 8
0
 /**
  * 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();
         }
     }
 }
Exemplo n.º 9
0
 /**
  * hSave cache
  *
  * @param	string	$id	Cache ID
  * @param	mixed	$data	Data to save
  * @param	int	$ttl	Time to live in seconds
  * @param	bool	$raw	Whether to store the raw value (unused)
  * @return	bool	TRUE on success, FALSE on failure
  */
 public function hsave($id, $key, $data)
 {
     if (is_array($data) or is_object($data)) {
         if (!$this->_redis->sIsMember('_ci_redis_serialized', $id) && !$this->_redis->sAdd('_ci_redis_serialized', $id)) {
             return FALSE;
         }
         isset($this->_serialized[$id]) or $this->_serialized[$id] = TRUE;
         $data = base64_encode(serialize($data));
     } elseif (isset($this->_serialized[$id])) {
         $this->_serialized[$id] = NULL;
         $this->_redis->sRemove('_ci_redis_serialized', $id);
     }
     return $this->_redis->hSet($id, $key, $data);
 }
Exemplo n.º 10
0
 /**
  * @param string $type
  * @param InputMessageIdentifier $identifier
  * @param OutputMessage $outputMessage
  */
 public function putOutput($type, InputMessageIdentifier $identifier, OutputMessage $outputMessage)
 {
     $messageId = $identifier->getId();
     $captureResult = 'MessageNotFinished' === $this->redis->hGet($this->getMessageResultKey($type), $messageId);
     $this->redis->multi();
     $this->redis->lRem($this->getMessageRunKey($type), $messageId, 0);
     $this->redis->hDel($this->getMessageStartTimeKey($type), $messageId);
     $this->redis->lRem($this->getMessageQueueKey($type), $messageId, 0);
     $this->redis->hDel($this->getMessageQueueTimeKey($type), $messageId);
     $this->redis->hDel($this->getMessageKey($type), $messageId);
     if ($captureResult) {
         $data = $outputMessage->getData();
         $this->redis->hSet($this->getMessageResultKey($type), $messageId, $data);
         $this->redis->lPush($this->getMessageResultReadyKey($type, $messageId), 'true');
     }
     $this->redis->exec();
 }
Exemplo n.º 11
0
 public function end($task)
 {
     $taskId = $task->getId();
     $captureResult = 'TaskNotFinished' === $this->redis->hGet($this->getTaskResultKey(), $taskId);
     $this->redis->multi();
     $this->redis->lRem($this->getTaskRunKey(), $taskId, 0);
     $this->redis->hDel($this->getTaskStartTimeKey(), $taskId);
     $this->redis->lRem($this->getTaskQueueKey(), $taskId, 0);
     $this->redis->hDel($this->getTaskQueueTimeKey(), $taskId);
     $this->redis->hDel($this->getTaskKey(), $taskId);
     if ($captureResult) {
         $taskResult = $task->getResult();
         $serializedTaskResult = serialize($taskResult);
         $this->redis->hSet($this->getTaskResultKey(), $taskId, $serializedTaskResult);
         $this->redis->lPush($this->getTaskResultReadyKey($taskId), 'true');
     }
     $this->redis->exec();
 }
Exemplo n.º 12
0
 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
 }
<?php

require_once __DIR__ . "/../../Bancard/autoload.php";
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);
$data = LlevaUno\Bancard\Core\Response::read()->get();
$response = json_decode($data);
$id = $response->operation->shop_process_id;
header('Content-Type: application/json');
if ($data) {
    $redis->hSet("LlevaUno:Bancard:PreAuthorization:PreAuthorization:{$id}", "confirm", $data);
    echo json_encode(array('status' => 200, 'message' => 'Success'));
} else {
    echo json_encode(array('status' => 404, 'message' => 'Not found'));
}
Exemplo n.º 14
0
 public function hSet($key, $field, $value)
 {
     return $this->connection->hSet($key, $field, $value);
 }
Exemplo n.º 15
0
 /**
  * 写用户规则.
  *
  * @param array  $matches_arr
  * @param string $hset_key
  */
 protected function write_user_matches_rules($matches_arr = array(), $hset_key = "")
 {
     $this->load->config('redis');
     $redis_config = $this->config->item('redis');
     $redis = new Redis();
     $redis->connect($redis_config['write']['hostname'], $redis_config['write']['port']);
     if (!empty($matches_arr)) {
         $redis->pipeline();
         foreach ($matches_arr as $match_key => $matches_val) {
             sort($matches_val);
             $rules_redis_key = "DY_matches_rules:" . $match_key . ":";
             $redis->hSet($rules_redis_key, $hset_key, json_encode($matches_val));
         }
         $redis->exec();
     }
     $redis->close();
 }
Exemplo n.º 16
0
<?php

//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
// $redis->flushAll();
// exit();
for ($index = $argv[1]; $index < $argv[2]; $index++) {
    $userKey = 'user' . $index;
    for ($i = 0; $i < 50; $i++) {
        $userField = 'field' . $i;
        $value = 'type:result' . $i;
        $redis->hSet($userKey, $userField, $value);
    }
    echo $index;
}
Exemplo n.º 17
0
 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']);
 }
Exemplo n.º 18
0
 /**
  * set var
  *
  * @param $key
  * @param null $value
  * @return boolean
  */
 public function set($key, $value)
 {
     return $this->redis->hSet($this->prefix, $key, $value);
 }
Exemplo n.º 19
0
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;
    }
}
Exemplo n.º 20
0
 /**
  * Set the value of a key.
  *
  * @param string $key The key to set the value of.
  * @param mixed $value The value.
  * @return bool True if the operation succeeded, false otherwise.
  */
 public function set($key, $value)
 {
     return $this->redis->hSet($this->hash, $key, $value) !== false;
 }
Exemplo n.º 21
0
<?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());
    }
}
Exemplo n.º 22
0
<?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));
Exemplo n.º 23
0
 /**
  * Save the workers arguments
  *
  * Used when restarting the worker
  *
  * @param  array $args Worker settings
  */
 public function addWorker($pid, $args)
 {
     return $this->redis->hSet(self::$workerKey, $pid, serialize($args)) !== false;
 }
Exemplo n.º 24
0
 /**
  * 设置任务属性
  *
  * @param string $key
  * @param string $val
  */
 protected function set($key, $val)
 {
     $this->injectors[$key] = $val;
     $this->client->hSet($this->queue->name . ':' . self::JOB_TAB . ':' . $this->injectors['id'], $key, $val);
 }
Exemplo n.º 25
0
 /**
  * @param string $key
  * @param string $member
  * @param string $value
  * @return int|FALSE
  */
 public function hSet($key, $member, $value)
 {
     return parent::hSet($key, $member, $value);
 }
}
// 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 {
        // If the lock is held by another user
        $return['status'] = 'locked';
        $return['action'] = 'none';
        $return['lockedBy'] = $curLockedBy;
        $return['ttl'] = $redis->ttl($keyName);
    }
} else {
    // If an unlock was requested