本篇文章主要给大家介绍关于php-redis常用命令总结,希望对需要的朋友有所帮助!
Keysdel
,delete
- 删除键dump
- 返回存储在指定键值的序列化版本。exists
- 确定键是否存在expire
,setTimeout
,pexpire
- 设置键的生存时间(以秒为单位)expireAt
,pexpireAt
- 将密钥的到期时间设置为UNIX时间戳keys
,getKeys
- 查找与给定模式匹配的所有键scan
- 扫描键空间中的键(Redis> = 2.8.0)migrate
- 将密钥从Redis实例原子传输到另一个实例move
- 将键移动到另一个数据库object
- 检查Redis对象的内部persist
- 从密钥中删除过期randomKey
- 从键空间返回随机密钥rename
,renameKey
- 重命名键renameNx
- 重命名键,仅当新键不存在时type
- 确定存储在键上的类型sort
- 对列表中的元素,集合或排序集进行排序ttl
,pttl
- 获取时间为一个键住restore
- 使用提供的序列化值创建密钥,以前通过dump获取。scan描述:扫描键的键空间返回:Array,boolean:如果没有更多的键,此函数将返回一个键的数组或FALSE
$it
= NULL;
/* Initialize our iterator to NULL */
$redis
->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
/* retry when we get no keys back */
while
(
$arr_keys
=
$redis
->scan(
$it
)) {
foreach
(
$arr_keys
as
$str_key
) {
echo
"Here is a key: $str_keyn"
;
}
echo
"No more keys to scan!n"
;
}
append
- 将值附加到键bitCount
- 计算字符串中的设置位bitOp
- 在字符串之间执行按位操作decr
,decrBy
- 递减键的值get
- 获取键的值getBit
- 返回在key处存储的字符串值中偏移处的位值getRange
- 获取存储在键上的字符串的子字符串getSet
- 设置键的字符串值并返回其旧值incr
,incrBy
- 递增键的值incrByFloat
- 将键的浮点值增加给定的量mGet
,getMultiple
- 获取所有给定键的值mSet
,mSetNX
- 将多个键设置为多个值set
- 设置键的字符串值setBit
- 设置或清除存储在键的字符串值中偏移处的位setEx
,pSetEx
- 设置键的值和过期时间setNx
- 设置键的值,仅当键不存在时setRange
- 在指定偏移处开始的键处覆盖字符串的一部分strLen
- 获取存储在键中的值的长度PSETEX描述:PSETEX使用以毫秒为单位的TTL
$ redis-> pSetEx(
'key'
,100,
'value'
);
//设置键→值,0.1秒TTL。
$redis
->setNx(
'key'
,
'value'
);
/* return TRUE */
$redis
->setNx(
'key'
,
'value'
);
/* return FALSE */
$redis
->incr(
'key1'
); / * key1不存在,在增加前设置为0 * /
/ *,现在的值为1 * /
$redis
->incr(
'key1'
);
/* 2 */
$redis
->incr(
'key1'
);
/* 3 */
$redis
->incr(
'key1'
);
/* 4 */
$redis
->incrBy(
'key1'
, 10);
/* 14 */
$redis
->incrByFloat(
'key1'
, 1.5);
/* key1 didn't exist, so it will now be 1.5 */
$redis
->incrByFloat(
'key1'
, 1.5);
/* 3 */
$redis
->incrByFloat(
'key1'
, -1.5);
/* 1.5 */
$redis
->incrByFloat(
'key1'
, 2.5);
/* 4 */
$redis
->set(
'key1'
,
'value1'
);
$redis
->set(
'key2'
,
'value2'
);
$redis
->set(
'key3'
,
'value3'
);
$redis
->mGet(
array
(
'key1'
,
'key2'
,
'key3'
)); /*
array
(
'value1'
,
'value2'
,
'value3'
);
$redis
->mGet(
array
(
'key0'
,
'key1'
,
'key5'
)); /*
array
(`FALSE`,
'value1'
, `FALSE`);
$redis
->set(
'x'
,
'42'
);
$exValue
=
$redis
->getSet(
'x'
,
'lol'
);
// return '42', replaces x by 'lol'
$newValue
=
$redis
->get(
'x'
)
' // return '
lol'
$redis
->select(0);
// switch to DB 0
$redis
->set(
'x'
,
'42'
);
// write 42 to x
$redis
->move(
'x'
, 1);
// move to DB 1
$redis
->select(1);
// switch to DB 1
$redis
->get(
'x'
);
// will return 42
$redis
->set(
'x'
,
'42'
);
$redis
->rename(
'x'
,
'y'
);
$redis
->get(
'y'
);
// → 42
$redis
->get(
'x'
);
// → `FALSE
$redis
->set(
'x'
,
'42'
);
$redis
->setTimeout(
'x'
, 3);
// x will disappear in 3 seconds.
sleep(5);
// wait 5 seconds
$redis
->get(
'x'
);
// will return `FALSE`, as 'x' has expired.
$redis
->set(
'x'
,
'42'
);
$now
= time(NULL);
// current timestamp
$redis
->expireAt(
'x'
,
$now
+ 3);
// x will disappear in 3 seconds.
sleep(5);
// wait 5 seconds
$redis
->get(
'x'
);
// will return `FALSE`, as 'x' has expired.