Redis,redis Getting Started Guide _php tutorial

Source: Internet
Author: User
Tags set set

Redis,redis Getting Started Guide


A sneak-in ...

1 
 Php2 /**3 * Description:redis4 * Create date:2015-10-11 17:275 * Author:zhaoyingnan6  **/7 8 /*9 __construct,__destruct,connect,pconnect,close,ping,echo,get,set,Ten Setex,psetex,setnx,getset,randomkey,renamekey,renamenx,getmultiple,exists,delete, One Incr,incrby,incrbyfloat,decr,decrby,type,append,getrange,setrange,getbit, A Setbit,strlen,getkeys,sort,sortasc,sortascalpha,sortdesc,sortdescalpha,lpush,rpush, - Lpushx,rpushx,lpop,rpop,blpop,brpop,lsize,lremove,listtrim,lget, - Lgetrange,lset,linsert,sadd,ssize,sremove,smove,spop,srandmember,scontains, the Smembers,sinter,sinterstore,sunion,sunionstore,sdiff,sdiffstore,settimeout,save,bgsave, - Lastsave,flushdb,flushall,dbsize,auth,ttl,pttl,persist,info,resetstat, - Select,move,bgrewriteaof,slaveof,object,bitop,bitcount,bitpos,mset,msetnx, - Rpoplpush,brpoplpush,zadd,zdelete,zrange,zreverserange,zrangebyscore,zrevrangebyscore,zcount, Zdeleterangebyscore, + Zdeleterangebyrank,zcard,zscore,zrank,zrevrank,zinter,zunion,zincrby,expireat,pexpire, - pexpireat,hget,hset,hsetnx,hdel,hlen,hkeys,hvals,hgetall,hexists, + Hincrby,hincrbyfloat,hmset,hmget,multi,discard,exec,pipeline,watch,unwatch, A Publish,subscribe,psubscribe,unsubscribe,punsubscribe,time,eval,evalsha,script,dump, at Restore,migrate,getlasterror,clearlasterror,_prefix,_serialize,_unserialize,client,scan,hscan, - Zscan,sscan,getoption,setoption,config,slowlog,gethost,getport,getdbnum,gettimeout, - Getreadtimeout,getpersistentid,getauth,isconnected,wait,pubsub,open,popen,llen,sgetmembers, - Mget,expire,zunionstore,zinterstore,zremove,zrem,zremoverangebyscore,zremrangebyscore,zremrangebyrank, Zsize, - Substr,rename,del,keys,lrem,ltrim,lindex,lrange,scard,srem, - Sismember,zrevrange,sendecho,evaluate,evaluatesha, in  */ - //How to work with Redis in PHP to $ReRedis=NewReflectionclass (' Redis '); + $arMethods=$ReRedis-GetMethods (); - $arMethods= Objarray_to_array ($arMethods); the //Print_r ($arMethods); * functionObjarray_to_array ($obj) {   $     $ret=Array(); Panax Notoginseng     foreach($obj  as $key=$value) {   -         if(GetType($value) = = "Array" | |GetType($value) = = "Object"){   the             $ret[$key] = Objarray_to_array ($value);  +}Else{   A             $ret[$key] =$value;  the         }   +     }   -     return $ret;  $ } $ $i= 1; - foreach($arMethods  as $arVal) -     Echo $arVal[' name '], ', '; the  - /****************************** Redis Introduction ************************************/Wuyi //Redis, a memory cache database with a data model of Key-value the //redis can be persisted (that is, it will save data from the hard disk) to ensure the security of the data - //redis Rich data type: string,list,hash,set,sorted set Wu  -  About /****************************** Redis and memcached compare ************************/ $ //Redis not only supports simple key-value, but also provides storage of data structures such as List,set,hash - //Redis support Master-slave (master-slave) mode application - //Redis support data persistence, can be in-memory data in the village spring in the hard drive, restart, power off when the data will not be lost - //Redis single value maximum limit of 1gb,memcached can only be saved in 1MB A  +  the /****************************** operation of the key in Redis *************************/ - /** $ * Eixists Key tests whether the specified key exists the * del key1 key2 Key3 ... Delete the given key the * Type key returns the value type of the given key the * Keys pattern returns all keys that match the specified pattern the * Rename oldkeyname newkeyname change name - * Dbsize Returns the number of keys for the current database in * Expire key seconds set expiration time for key the * TTL key returns the remaining expiration time of key the * Select Db-index Database (0-15) About * Move key Db-index moves key from the current database to the specified database the * FLUSHDB Delete all keys in the current database the * Flushall Delete all keys in all databases the  **/ +  -  the /****************************** The operation of string types in Redis ********************/Bayi /** the * Set key value setting key corresponds to value of string type the * Mset key1 value1 key2 value2 KeyN Valuen set values for multiple keys at once - * mget key1 key2 KeyN get multiple key values at once - * incr key to self-increment the value of key, step value is 1, and return the new value the * DECR key self-decrement the value of key, the step value is 1, and returns the new value the * Incrby key integer with INCR, but the stepping value is the specified integer, and the new value is returned the * Decrby key integer with DECR, but the stepping value is the specified integer, and the new value is returned the * Append key value appends value to the specified key - * substr Key start end returns the value corresponding to the truncated key, including the start and end positions, with the subscript starting at 0 the  **/ the  the 94 /****************************** operation of the list type in Redis ***********************/ the //The list type is a doubly linked list that adds or removes elements from the head or tail of the list through the Push,pop operation.  the //Application scenario: Get the latest logged in 10 users information the /**98 * Lpush Key value adds the value element to the head of the list for the key, returning the number of elements in the list About * Rpush Key value adds the value element at the end of the list for the key, returning the number of elements in the list - * Rpop key Deletes an element at the tail of the list corresponding to the key and returns the contents of the element101 * Lpop key Deletes an element at the head of the list corresponding to the key and returns the contents of the element102 * Llen Key returns the number of elements in the list for the key, or 0 if it does not exist, or if the list type is not an error103 * Lrange Key start end returns the element within the specified range of the list of keys, including the start and end positions, subscript starting from 0104 * LTrim key Start key intercepts list, preserving elements within a specified range the  **/106 107 108 /****************************** operation of the set type in Redis *************************/109 //set unordered collection, the elements of each collection will not be duplicated, can contain up to 2 of the 32 elements (intersection, set, difference set) the //Application scenario: QQ friend referral, you and Zhang San's common friend111 /** the * Sadd Key member adds a member element to the set set of key corresponding to the successful return 1, if the element already exists, returns 0113 * Sren key member1 Membern removes the given element from the set set of key and returns 1 successfully the * SCard Key returns the number of elements in the set set corresponding to key the * Smembers Key returns all elements in the set set of key, which are unordered the * Sismember Key member determine if member exists in the set set of key, there is a return of 1, otherwise 0117 * Smove key1 key2 member moves key1 in member corresponding set set to Key2 corresponding set set118 * sinter key1 key2 KeyN Returns the intersection of the set set corresponding to all given key119 * sunion key1 key2 KeyN Returns the set of sets for all given keys - * Sdiff key1 key2 KeyN Returns the difference set of set set for all given key121  **/122 123 124 /****************************** operation of sorted set type in Redis *******************/ the //A set of sorted set, unlike a set set, in which each element in each collection is a combination of values and weights126 //Application scenario: Leaderboard127 /** - * Zadd key score member add element to key corresponding set set, where value is member, weight is score129 * Zrem Key member Delete the specified element in the set set corresponding to key member the * Zincrby Key INCR member increments the member weight value of the score element in the set set of the key corresponding to the incr amplitude131 * Zrank Key member returns the specified element member in the set set of key corresponding to the subscript, ranking by score small to large, subscript 0 open the * Zrevrank Key member returns the specified element member the rank subscript in the set set of key, ranking by score large to small, subscript 0 open133 * Zrange Key start end returns the value of the element of the specified interval in the corresponding set set of key, sort Ann score small to large, subscript 0 open, with the whole story134 * Zrevrange Key start end returns the value of the element of the specified interval in the corresponding set set of key, sort Ann score large to small, subscript 0 open, with the whole story135 * Zcard Key returns the number of elements in the set set corresponding to key136 * Zscore Key member returns the value of the score of the element given in the set set of the key corresponding to member137 * Zremrangebyrank key min Max deletes the element in the set set of keys corresponding to the given interval (by score small to large sort)138  **/139  $ 141 /****************************** Redis Data Persistence ************************************/142 /**143 * Snap shotting snapshot Persistence144 * This feature is enabled by default, all data in Redis is saved in one copy on the hard disk, so the data is not suitable for frequent operation .145 * redis.conf146 * Snapshot Persistent backup frequency (data modification frequency high/low, backup frequency is also high/low)147 * Save 1 #900 seconds if more than 1 keys are modified, a snapshot save is initiated148 * Save in #300 seconds if more than 10 keys are modified, a snapshot save is initiated149 * Save 10000 #60 seconds if more than 10,000 keys are modified, a snapshot save is initiated Max * Dbfilename Dump.rdb #备份的文件名称151 * dir./#备份文件的保存路径 the * Manually initiating a snapshot persistence153 * redis-cli-h 127.0.0.1-p 6379 bgsave #手动发起一次快照持久化154  **/155 156 /**157 * Append only file aof persistent158 * Essence: The user executes every ' write ' command back to the file, restore the data is actually the implementation of specific instructions159 * default is not turned on, the data in Redis will be emptied and opened before use . the * redis.conf161 * AppendOnly no #默认不开启162 * appendfilename "appendonly.aof" #备份文件的名称163 * dir./#备份文件的保存路径164 * When you turn on AOF persistence, you should restart Redis using the corresponding configuration file165 * Redis-server redis.conf166 * AOF Persistent backup frequency167 * redis.conf168 * # Appendfsync always #每次收到写指令就会立即备份, safest, but slowest, with great overhead169 * Appendfsync everysec #每秒钟强制备份一次, a compromise in performance and persistence, default the * # Appendfsync No #完全依赖操作系统, best performance, no guarantee for durability, worst security171 * Optimized compression processing for AOF backup files172 * For example, to change multiple INCR instructions into a set instruction173 * redis-cli-h 127.0.0.1-p 6379 bgrewriteaof #优化压缩174  **/

http://www.bkjia.com/PHPjc/1059459.html www.bkjia.com true http://www.bkjia.com/PHPjc/1059459.html techarticle Redis,redis Getting Started Guide sneak in ... 1? PHP 2/* * 3 * Description:redis 4 * Create date:2015-10-11 17:27 5 * Author:zhaoyingnan 6 * */7 8/* 9 __construct,__d Estruct,c ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.