当前位置:网站首页>Summary of redis Functions PHP version
Summary of redis Functions PHP version
2022-06-23 22:09:00 【It workers】
<?php
/*1.Connection*/
$redis = new Redis();
$redis->connect('127.0.0.1',6379,1);// Short link , Local host, Port is 6379, exceed 1 Second discard link
$redis->open('127.0.0.1',6379,1);// Short link ( ditto )
$redis->pconnect('127.0.0.1',6379,1);// Long link , Local host, Port is 6379, exceed 1 Second discard link
$redis->popen('127.0.0.1',6379,1);// Long link ( ditto )
$redis->auth('password');// Login to verify password , return 【true | false】
$redis->select(0);// choice redis library ,0~15 common 16 Databases
$redis->close();// Release resources
$redis->ping(); // Check to see if there are any more links ,[+pong]
$redis->ttl('key');// Check the expiration time [-1 | timestamps]
$redis->persist('key');// Remove the expiration time [ 1 | 0]
$redis->sort('key',[$array]);// Returns or saves the given list 、 aggregate 、 Ordered set key The ordered elements in ,$array Is the parameter limit etc. !【 coordination $array Very powerful 】 [array|false]
/*2. Common operation classification */
$redis->expire('key',10);// Set the expiration time [true | false]
$redis->move('key',15);// Put... In the current library key Move to 15 In the library [0|1]
//string
$redis->strlen('key');// Get current key The length of
$redis->append('key','string');// hold string Append to key The existing value in [ Number after addition ]
$redis->incr('key');// Self increasing 1, If there is no key, The assignment is 1( Valid only for integers , Store in 10 Base number 64 position ,redis In Chinese, it means str)[new_num | false]
$redis->incrby('key',$num);// Self increasing $num, There is no assignment for , Value must be an integer [new_num | false]
$redis->decr('key');// Self reduction 1,[new_num | false]
$redis->decrby('key',$num);// Self reduction $num,[ new_num | false]
$redis->setex('key',10,'value');//key=value, Valid for 10 second [true]
//list
$redis->llen('key');// Returns a list of key The length of , non-existent key return 0, [ len | 0]
//set
$redis->scard('key');// Back to the assembly key Base number of ( Number of elements in the collection ).[num | 0]
$redis->sMove('key1', 'key2', 'member');// Move , take member Elements from key1 The assembly moves to key2 aggregate .[1 | 0]
//Zset
$redis->zcard('key');// Back to the assembly key Base number of ( Number of elements in the collection ).[num | 0]
$redis->zcount('key',0,-1);// Return to ordered set key in ,score Values in min and max Between ( The default include score The value is equal to min or max) Members of .[num | 0]
//hash
$redis->hexists('key','field');// see hash Whether there is field,[1 | 0]
$redis->hincrby('key','field',$int_num);// Hash table key In the domain field The value of plus the amount (+|-)num,[new_num | false]
$redis->hlen('key');// Return hash table key Number of domains .[ num | 0]
/*3.Server*/
$redis->dbSize();// Returns... In the current library key The number of
$redis->flushAll();// Empty the whole redis[ total true]
$redis->flushDB();// To empty the current redis library [ total true]
$redis->save();// Sync ?? Store data on disk -dump.rdb[true]
$redis->bgsave();// asynchronous ?? Store data on disk -dump.rdb[true]
$redis->info();// Query the current redis The state of [verson:2.4.5....]
$redis->lastSave();// Last stored time key Time for [timestamp]
$redis->watch('key','keyn');// Watch one ( Or more ) key , If before the transaction is executed ( Or these ) key Altered by other orders , Then the business will be interrupted [true]
$redis->unwatch('key','keyn');// Cancel monitoring a ( Or more ) key [true]
$redis->multi(Redis::MULTI);// Open transaction , Multiple commands in a transaction block are put into a queue in sequence , Finally by EXEC The command is executed in one atomic time .
$redis->multi(Redis::PIPELINE);// Pipe opening , Multiple commands in a transaction block are put into a queue in sequence , Finally by EXEC The command is executed in one atomic time .
$redis->exec();// Execute commands within all transaction blocks ,;【 The return value of all commands in the transaction block , In the order in which the orders are executed , When the operation is interrupted , Returns a null value false】
/*4.String, Key value pair , Creating and updating is the same as */
$redis->setOption(Redis::OPT_PREFIX,'hf_');// Set the table prefix to hf_
$redis->set('key',1);// Set up key=aa value=1 [true]
$redis->mset($arr);// Set one or more key values [true]
$redis->setnx('key','value');//key=value,key There is returned false[|true]
$redis->get('key');// obtain key [value]
$redis->mget($arr);//(string|arr), Returns the value of the queried key
$redis->del($key_arr);//(string|arr) Delete key, Supports batch deletion of arrays 【 Return the number of deletions 】
$redis->delete($key_str,$key2,$key3);// Delete keys,[del_num]
$redis->getset('old_key','new_value');// Get it first key Value , And then reassign ,[old_value | false]
/*5.List The structure of the stack , Pay attention to the header and footer , Create and update separate operations */
$redis->lpush('key','value');// increase , Only one value can be value Insert into list key The header , Create... If it doesn't exist [ The length of the list |false]
$redis->rpush('key','value');// increase , Only one value can be value Insert into list key At the end of the watch [ The length of the list |false]
$redis->lInsert('key', Redis::AFTER, 'value', 'new_value');// increase , Will value value Insert into list key among , At value value Before or after .[new_len | false]
$redis->lpushx('key','value');// increase , Only one value can be value Insert into list key The header , Does not exist, does not create [ The length of the list |false]
$redis->rpushx('key','value');// increase , Only one value can be value Insert into list key At the end of the watch , Does not exist, does not create [ The length of the list |false]
$redis->lpop('key');// Delete , Remove and return to list key The head element of ,[ Deleted element | false]
$redis->rpop('key');// Delete , Remove and return to list key The tail element ,[ Deleted element | false]
$redis->lrem('key','value',0);// Delete , According to the parameters count Value , Remove the list and parameters value Equal elements count=(0|-n Head to tail |+n The end of the watch is removed from the head n individual value) [ Number removed | 0]
$redis->ltrim('key',start,end);// Delete , List pruning , Retain (start,end) Between the value of the [true|false]
$redis->lset('key',index,'new_v');// Change , Count from header , Will list key The subscript is no index The value of the element of is new_v, [true | false]
$redis->lindex('key',index);// check , Returns a list of key in , Subscript to be index The elements of [value|false]
$redis->lrange('key',0,-1);// check ,(start,stop|0,-1) Returns a list of key The elements in the specified interval , The interval is offset by start and stop Appoint .[array|false]
/*6.Set, No repeat member, Creating and updating is the same as */
$redis->sadd('key','value1','value2','valuen');// increase , Change , Put one or more member Elements are added to the collection key among , Existing in a collection member Elements will be ignored .[insert_num]
$redis->srem('key','value1','value2','valuen');// Delete , Remove set key One or more of them member Elements , There is no the member Elements will be ignored [del_num | false]
$redis->smembers('key');// check , Back to the assembly key All members of [array | '']
$redis->sismember('key','member');// Judge member Is the element a collection key Members of [1 | 0]
$redis->spop('key');// Delete , Remove and return a random element from the collection [member | false]
$redis->srandmember('key');// check , Returns a random element in the set [member | false]
$redis->sinter('key1','key2','keyn');// check , Returns the intersection of all given sets [array | false]
$redis->sunion('key1','key2','keyn');// check , Returns the union of all given sets [array | false]
$redis->sdiff('key1','key2','keyn');// check , Returns the difference set of all given sets [array | false]
/*7.Zset, No repeat member, There is a sort order , Creating and updating is the same as */
$redis->zAdd('key',$score1,$member1,$scoreN,$memberN);// increase , Change , Put one or more member Elements and score Value added to ordered set key among .[num | 0]
$redis->zrem('key','member1','membern');// Delete , Remove ordered sets key One or more members of , Members that do not exist will be ignored .[del_num | 0]
$redis->zscore('key','member');// check , Take power through value inversion [num | null]
$redis->zrange('key',$start,$stop);// check , adopt (score From small to large )【 Sort rank range 】 take member value , Return to ordered set key in ,【 Within the specified range 】 Members of [array | null]
$redis->zrevrange('key',$start,$stop);// check , adopt (score From big to small )【 Sort rank range 】 take member value , Return to ordered set key in ,【 Within the specified range 】 Members of [array | null]
$redis->zrangebyscore('key',$min,$max[,$config]);// check , adopt scroe The scope of authority is member value , Return to ordered set key in , Within a specified interval ( From small to large ) member [array | null]
$redis->zrevrangebyscore('key',$max,$min[,$config]);// check , adopt scroe The scope of authority is member value , Return to ordered set key in , Within a specified interval ( From big to small row ) member [array | null]
$redis->zrank('key','member');// check , adopt member It's worth checking (score From small to large ) In the ranking results 【member Sort ranking 】[order | null]
$redis->zrevrank('key','member');// check , adopt member It's worth checking (score From big to small ) In the ranking results 【member Sort ranking 】[order | null]
$redis->ZINTERSTORE();// intersection
$redis->ZUNIONSTORE();// Difference set
/*8.Hash, Table structure , Creating and updating is the same as */
$redis->hset('key','field','value');// increase , Change , Hash table key In the domain field The value of the set value, There is no creation , Existence covers 【1 | 0】
$redis->hget('key','field');// check , Value 【value|false】
$arr = array('one'=>1,2,3);$arr2 = array('one',0,1);
$redis->hmset('key',$arr);// increase , Change , Set multiple values $arr by ( Indexes | relation ) Array ,$arr[key]=field, [ true ]
$redis->hmget('key',$arr2);// check , Gets the field,[$arr | false]
$redis->hgetall('key');// check , Return hash table key All fields and values in .[ When key When there is no , Returns an empty table ]
$redis->hkeys('key');// check , Return hash table key All domains in .[ When key When there is no , Returns an empty table ]
$redis->hvals('key');// check , Return hash table key All the values in .[ When key When there is no , Returns an empty table ]
$redis->hdel('key',$arr2);// Delete , Delete the specified subscript field, Domains that do not exist will be ignored ,[num | false]
?>
边栏推荐
- Analysis of a series a e-commerce app docommandnative
- What is stock online account opening? Is it safe to open a mobile account?
- [emergency] log4j has released a new version of 2.17.0. Only by thoroughly understanding the cause of the vulnerability can we respond to changes with the same method
- Second kill design of 100 million level traffic architecture
- 智能座舱SoC竞争升级,国产7nm芯片迎来重要突破
- Important announcement: Tencent cloud es' response strategy to log4j vulnerability
- Selenium batch query athletes' technical grades
- Interpretation of opentelemetry project
- Dart series: look at me for security. The security feature in dart is null safety
- Digital transformation solution for supply chain platform of mechanical equipment industry
猜你喜欢

北大、加州伯克利大學等聯合| Domain-Adaptive Text Classification with Structured Knowledge from Unlabeled Data(基於未標記數據的結構化知識的領域自適應文本分類)

How to calculate individual income tax? You know what?

Outlook開機自啟+關閉時最小化

Teacher lihongyi from National Taiwan University - grade Descent 2

Cloud native practice of meituan cluster scheduling system

Error running PyUIC: Cannot start process, the working directory ‘-m PyQt5. uic. pyuic register. ui -o

Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)

How to use the serial port assistant in STC ISP?

Installation and use of Minio

微信小程序中发送网络请求
随机推荐
EDI mandatory manual
How to select Poe, poe+, and poe++ switches? One article will show you!
What causes the applet SSL certificate to expire? How to solve the problem when the applet SSL certificate expires?
Raid card with hardware knowledge (5)
HR SaaS is finally on the rise
Flink practical tutorial: advanced 4-window top n
[proteus simulation] lcd1602+ds1307 key setting simple clock
Configuring error sets using MySQL for Ubuntu 20.04.4 LTS
How to use zero to build a computer room
Lighthouse open source application practice: snipe it
How to realize batch generation of serial number QR code
WordPress plug-in recommendation
Simple code and design concept of "back to top"
How to improve the content quality of short video, these four elements must be achieved
Practice of business level disaster recovery switching drill
How to solve the loss of video source during easynvr split screen switching?
How to set the life cycle of API gateway
How does the hybrid cloud realize the IP sec VPN cloud networking dedicated line to realize the interworking between the active and standby intranet?
Polar cycle graph and polar fan graph of high order histogram
Redis encapsulation instance