本文整理汇总了PHP中Redis::hset方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::hset方法的具体用法?PHP Redis::hset怎么用?PHP Redis::hset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::hset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHScan
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);
}
示例2: setting
/**
* 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);
}
示例3: testHashes
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']);
//.........这里部分代码省略.........
示例4: hset
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));
}
示例5: doLog
/**
* @inheritdoc
*/
protected function doLog($ident, $originalId, array $context)
{
$this->redis->hset($ident, $originalId, json_encode($context));
}
示例6: setCache
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
//.........这里部分代码省略.........
示例7: hset
/**
* 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);
}
示例8: array
$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);
示例9: count
$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) {
示例10: 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(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']);
}
示例11: hset
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;
}
示例12: Redis
<?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';
}
示例13: hset
public function hset($key, $hash, $value, $serialize = true)
{
$value = $serialize ? serialize($value) : $value;
return $this->handler->hset($key, $hash, $value);
}
示例14: log
/**
* @inheritdoc
*/
public function log($id, $originalId, array $context)
{
$this->redis->hset($id, $originalId, json_encode($context));
}
示例15: Redis
} 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);
}
}
}
}
}
}
}
}