本文整理汇总了PHP中Redis::mset方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::mset方法的具体用法?PHP Redis::mset怎么用?PHP Redis::mset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::mset方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
/**
* 存数据,支持多存
*
* @param string/array $key
* @param $data Value 多存时此项可空
* @return boolean
*/
public function set($key, $value = null)
{
$this->_connect();
Core::debug()->info($key, 'storage redis set key');
if (is_array($key)) {
foreach ($key as &$item) {
$this->_format_data($item);
}
return $this->_redis->mset($key);
} else {
$this->_format_data($value);
return $this->_redis->set($key, $value);
}
}
示例2: set
/**
* 存数据,支持多存
*
* @param string/array $key
* @param $data Value 多存时此项可空
* @param $lifetime 有效期,默认3600,即1小时,0表示最大值30天(2592000)
* @return boolean
*/
public function set($key, $value = null, $lifetime = 3600)
{
$this->_connect();
Core::debug()->info($key, 'redis set key');
if (is_array($key)) {
foreach ($key as &$item) {
Cache_Driver_Redis::_format_data($item);
}
return $this->_redis->mset($key);
} else {
Cache_Driver_Redis::_format_data($value);
return $this->_redis->set($key, $value, $lifetime);
}
}
示例3: mset
/**
* {@inheritdoc}
*/
public function mset(array $data, $ttl = 0)
{
if ($ttl === 0) {
if ($this->redis->mset($data)) {
return count($data);
}
return 0;
}
$count = 0;
foreach ($data as $key => $value) {
if ($this->set($key, $value, $ttl)) {
$count++;
}
}
return $count;
}
示例4: testMset
public function testMset()
{
$this->redis->delete('x', 'y', 'z');
// remove x y z
$this->assertTrue($this->redis->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c')));
// set x y z
$this->assertEquals($this->redis->mget(array('x', 'y', 'z')), array('a', 'b', 'c'));
// check x y z
$this->redis->delete('x');
// delete just x
$this->assertTrue($this->redis->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c')));
// set x y z
$this->assertEquals($this->redis->mget(array('x', 'y', 'z')), array('a', 'b', 'c'));
// check x y z
$this->assertFalse($this->redis->mset(array()));
// set ø → FALSE
}
示例5: tag
/**
* @param string $keys
* @param array|string[] $tags
*
* @return bool
*/
public function tag($keys, array $tags = array())
{
if (empty($tags)) {
return true;
}
if (!is_array($keys)) {
$keys = array($keys);
}
$tags = $this->flattenTags($tags);
$serializedTags = $this->serialize($tags);
$nsTagsKeys = $this->applyNamespace($keys, 'tags');
$values = array_combine($nsTagsKeys, array_fill(0, count($nsTagsKeys), $serializedTags));
$this->client->mset($values);
$nsTags = $this->applyNamespace($tags, 'tag');
foreach ($nsTags as $nsTag) {
call_user_func_array(array($this->client, 'sAdd'), array_merge(array($nsTag), $keys));
}
}
示例6: set
/**
* 存数据,支持多存
*
* @param string/array $key
* @param mixed $data Value 多存时此项可空
* @param int $lifetime 有效期,默认3600,即1小时,0表示最大值
* @return boolean
*/
public function set($key, $value = null, $lifetime = 3600)
{
$this->_connect();
Core::debug()->info($key, 'cache redis set key');
if (is_array($key)) {
foreach ($key as &$item) {
$this->_format_data($item);
}
if ($lifetime) {
$rs = true;
foreach ($key as $k => $v) {
if (!$this->_redis->set($k, $v, $lifetime)) {
$rs = false;
}
}
} else {
$rs = $this->_redis->mset($key);
}
return $rs;
} else {
$this->_format_data($value);
return $this->_redis->set($key, $value, $lifetime);
}
}
示例7: 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
}
示例8: test4Action
public function test4Action()
{
$redis = new Redis();
$redis->connect("127.0.0.1", "6379");
//php客户端设置的ip及端口
//存储一个 值
$redis->set("say", "Hello World");
echo $redis->get("say");
//应输出Hello World
//存储多个值
$array = array('first_key' => 'first_val', 'second_key' => 'second_val', 'third_key' => 'third_val');
$array_get = array('first_key', 'second_key', 'third_key');
$redis->mset($array);
var_dump($redis->mget($array_get));
die;
}
示例9: mset
/**
* 同时给多个key赋值
* @param $data array key值数组 array('key0'=>'value0','key1'=>'value1')
*/
public static function mset($data)
{
$redis = new \Redis();
$redis->connect(self::_HOST, self::_PORT);
$return = null;
$return = $redis->mset($data);
$redis->close();
$redis = null;
return $return;
}
示例10: Redis
<?php
$redis = new Redis();
$redis->connect("127.0.0.1", "6379");
// string
$redis->delete("KeyTime");
$redis->mset(array('key111' => "key111", "key222" => "key222"));
echo (int) $redis->exists("key111");
$array = $redis->getMultiple(array("key111", "key222"));
echo "<br>";
print_r($array);
for ($i = 0; $i < 10; $i++) {
$redis->lpush("list", $i);
}
$redis->lpop("list");
$redis->rpop("list");
echo $redis->lsize("list");
echo $redis->lget("list", 0);
echo $redis->lset("list", 1, "new_value");
$data = $redis->lRange("list", 0, -1);
echo "<pre>";
print_r($data);
$bool = $redis->ltrim("list", 0, 5);
echo $redis->lrem("list", "5");
$bool = $redis->rpoplpush("srcKey", "dstKey");
// SET
for ($i = 0; $i < 10; $i++) {
$redis->sadd("myset", $i + rand(10, 99));
}
$bool = $redis->srem("myset", 16);
echo (int) $bool;