当前位置:网站首页>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]
?>
边栏推荐
- How to select Poe, poe+, and poe++ switches? One article will show you!
- KnowDA: All-in-One Knowledge Mixture Model for Data Augmentation in Few-Shot NLP(KnowDA:用于 Few-Shot NLP 中数据增强的多合一知识混合模型)
- Dart series: look at me for security. The security feature in dart is null safety
- Polar cycle graph and polar fan graph of high order histogram
- How to do API gateway routing? What are the other functions of API gateway?
- What causes the applet SSL certificate to expire? How to solve the problem when the applet SSL certificate expires?
- Second kill design of 100 million level traffic architecture
- SAP retail transaction code mp38 can perform forecasts for multiple items
- What is the use of PMP certification?
- [log service CLS] one click to start the efficient operation and maintenance journey of Tencent E-Sign
猜你喜欢

Analysis of Alibaba cloud Tianchi competition -- prediction of o2o coupon

Installation and use of Minio

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading

Leetcode must review six lintcode (28348455116385)

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

实验五 模块、包和库

Cloud native practice of meituan cluster scheduling system

Bluetooth chip | Renesas and Ti launch new Bluetooth chip, try Lenz st17h65 Bluetooth ble5.2 chip

《scikit-learn机器学习实战》简介

Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)
随机推荐
Smart cockpit SOC competition upgraded, and domestic 7Nm chips ushered in an important breakthrough
Code implementation of CAD drawing online web measurement tool (measuring distance, area, angle, etc.)
Minimize outlook startup + shutdown
Environment construction of go language foundation
How does the API gateway intercept requests? How does the security of the API gateway reflect?
How to defend the security importance of API gateway
使用 Provider 改造屎一样的代码,代码量降低了2/3!
How to realize batch generation of serial number QR code
德国弗莱堡大学、希尔德斯海姆大学等联合 | Zero-Shot AutoML with Pretrained Models(基于预训练模型的零样本AutoML)
[same origin policy - cross domain issues]
How to write test cases efficiently?
A batch layout WAF script for extraordinary dishes
The 10th Blue Bridge Cup single chip microcomputer
[proteus simulation] lcd1602+ds1307 key setting simple clock
How API gateway extends the importance of gateway extension
API gateway verification token the role of adding a new authentication token in API gateway
Tdsql elite challenge CVM voucher usage guide
One article to help you understand automatic injection
Analysis of a series a e-commerce app docommandnative
What is the reason for the error when calling API prompt 401 after easycvr replaces the version?