本文整理汇总了PHP中Redis::type方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::type方法的具体用法?PHP Redis::type怎么用?PHP Redis::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::type方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: type
/**
* 返回该k的数据类型
* @example string: Redis::REDIS_STRING sets: Redis::REDIS_SET list: Redis::REDIS_LIST zsets: Redis::REDIS_ZSET hashes: Redis::REDIS_HASH other: Redis::REDIS_NOT_FOUND
* @return string sets|string|list|zsets|hashes|other
*/
public function type()
{
try {
$redisType = $this->rd->type($this->k);
} catch (\RedisException $e) {
if ($this->reconnRedis()) {
$redisType = $this->rd->type($this->k);
} else {
$redisType = '';
}
}
switch ($redisType) {
case \Redis::REDIS_SET:
return 'sets';
case \Redis::REDIS_HASH:
return 'hashes';
case \Redis::REDIS_LIST:
return 'list';
case \Redis::REDIS_STRING:
return 'string';
case \Redis::REDIS_ZSET:
return 'zsets';
case \Redis::REDIS_NOT_FOUND:
default:
return 'other';
}
}
示例2: setSavesSetDataTypeForTagToIdentifiersSet
/**
* @test Implementation
*/
public function setSavesSetDataTypeForTagToIdentifiersSet()
{
$this->setUpBackend();
$this->setUpRedis();
$identifier = 'identifier' . uniqid();
$tag = 'tag';
$this->backend->set($identifier, 'data', array($tag));
$this->assertSame(\Redis::REDIS_SET, $this->redis->type('tagIdents:' . $tag));
}
示例3: testType
public function testType()
{
// 0 => none, (key didn't exist)
// 1=> string,
// 2 => set,
// 3 => list
// string
$this->redis->set('key', 'val');
$this->assertEquals(Redis::REDIS_STRING, $this->redis->type('key'));
// list
$this->redis->lPush('keyList', "val0");
$this->redis->lPush('keyList', "val1");
$this->assertEquals(Redis::REDIS_LIST, $this->redis->type('keyList'));
// set
$this->redis->delete('keySet');
$this->redis->sAdd('keySet', "val0");
$this->redis->sAdd('keySet', "val1");
$this->assertEquals(Redis::REDIS_SET, $this->redis->type('keySet'));
//None
$this->assertEquals(Redis::REDIS_NOT_FOUND, $this->redis->type('keyNotExists'));
}
示例4: testType
public function testType()
{
// 0 => none, (key didn't exist)
// 1=> string,
// 2 => set,
// 3 => list,
// 4 => zset,
// 5 => hash
// string
$this->redis->set('key', 'val');
$this->assertEquals(Redis::REDIS_STRING, $this->redis->type('key'));
// list
$this->redis->lPush('keyList', 'val0');
$this->redis->lPush('keyList', 'val1');
$this->assertEquals(Redis::REDIS_LIST, $this->redis->type('keyList'));
// set
$this->redis->delete('keySet');
$this->redis->sAdd('keySet', 'val0');
$this->redis->sAdd('keySet', 'val1');
$this->assertEquals(Redis::REDIS_SET, $this->redis->type('keySet'));
// sadd with numeric key
$this->redis->delete(123);
$this->assertTrue(1 === $this->redis->sAdd(123, 'val0'));
$this->assertTrue(array('val0') === $this->redis->sMembers(123));
// zset
$this->redis->delete('keyZSet');
$this->redis->zAdd('keyZSet', 0, 'val0');
$this->redis->zAdd('keyZSet', 1, 'val1');
$this->assertEquals(Redis::REDIS_ZSET, $this->redis->type('keyZSet'));
// hash
$this->redis->delete('keyHash');
$this->redis->hSet('keyHash', 'key0', 'val0');
$this->redis->hSet('keyHash', 'key1', 'val1');
$this->assertEquals(Redis::REDIS_HASH, $this->redis->type('keyHash'));
//None
$this->assertEquals(Redis::REDIS_NOT_FOUND, $this->redis->type('keyNotExists'));
}
示例5: testType
public function testType()
{
$this->redis->set('key', 'val');
$this->assertEquals(1, $this->redis->type('key'));
}
示例6: Redis
<?php
$redis = new Redis();
#实例化redis类
$redis->connect('127.0.0.1');
#连接服务器
$redis->set('key', 'hello ');
#调用方法,设置string类型值
$redis->append('key', 'world');
#修改string类型值
echo $redis->get('key');
#获取redis key的值,并输出显示
echo $redis->type('key');
#获取key 的数据类型
echo $redis->echo('will close...');
# 输出字符串
$redis->close();
#关闭连接
//脚本结束的时候,资源都被释放了,一般都不写close。
示例7: Redis
<?php
$redis = new Redis();
$redis->connect('127.0.0.1');
$redis->set('hello', 'hehanlin');
echo $redis->get('hello');
echo $redis->type('hello');
$redis->close();
示例8: rand
$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);
$redis->settimeout("user:1", 10);
$redis->expireat("myhash", time() + 23);
$count = $redis->dbSize();
$redis->auth("foobared");
$redis->bgrewriteaof();
$redis->slaveof("10.0.1.7", 6379);
print_r($redis->info());
echo $redis->type("myset");