Keys
del,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
参考网址:http://stackoverflow.com/questions/19910527/how-to-use-hscan-command-in-redis
$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_key/n echo No more keys to scan!/n }
Strings
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。
setNx
描述:如果键在数据库中不存在,则将参数中的字符串值设置为键的值。
$redis- setNx( key , value /* return TRUE */$redis- setNx( key , value /* return FALSE */
incr, incrBy
描述:将存储在键上的数字增加1。 如果第二个参数被填充,它将被用作增量的整数值。
$redis- incr( key1 / * key1不存在,在增加前设置为0 * / / *,现在的值为1 * /$redis- incr( key1 /* 2 */$redis- incr( key1 /* 3 */$redis- incr( key1 /* 4 */$redis- incrBy( key1 , 10); /* 14 */
incrByFloat
描述:使用浮点精度递增键
$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 */
mGet, getMultiple
描述:获取所有指定键的值。 如果一个或多个键不存在,数组将在键的位置包含FALSE。
$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`);
getSet
描述:设置一个值并返回该键上的上一个条目。
$redis- set( x , 42 $exValue = $redis- getSet( x , lol // return 42 , replaces x by lol $newValue = $redis- get( x ) // return lol
move
描述:将键移动到其他数据库。
$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
rename, renameKey
描述:
$redis- set( x , 42 $redis- rename( x , y $redis- get( y // → 42$redis- get( x // → `FALSE
renameNx
描述:与重命名相同,但如果目标已存在,则不会替换密钥。 这与setNx的行为相同。
$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.
expireAt, pexpireAt
这个适合设置从Unix时间戳。 钥匙的死亡日期,从纪元时间起的秒数。
描述:在项目上设置到期日期(时间戳)。 pexpireAt需要一个以毫秒为单位的时间戳。
$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.
以上就是php-redis常用命令总结的详细内容,PHP教程
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答