本文整理汇总了PHP中Redis::hSet方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::hSet方法的具体用法?PHP Redis::hSet怎么用?PHP Redis::hSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::hSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRedisCategoryDescription
/**
* 获取订单数据
* @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']);
}
}
示例2: set
/**
* {@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));
}
示例3: gauge
/**
* @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');
}
示例4: release
/**
* @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);
}
示例5: setCached
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);
}
}
}
示例6: testPerfDirectRedis
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__);
}
示例7: testHashes
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'));
*/
}
示例8: handle
/**
* 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();
}
}
}
示例9: hsave
/**
* 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);
}
示例10: putOutput
/**
* @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();
}
示例11: end
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();
}
示例12: checkSerializer
//.........这里部分代码省略.........
// 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
}
示例13: Redis
<?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'));
}
示例14: hSet
public function hSet($key, $field, $value)
{
return $this->connection->hSet($key, $field, $value);
}
示例15: write_user_matches_rules
/**
* 写用户规则.
*
* @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();
}