Getting started with Redis and redis _ PHP Tutorial

Source: Internet
Author: User
Redis and redis Getting Started Guide. Redis, redis Getting Started Guide busy ah... 1? Php2 ** 3 * Description: Redis4 * Createdate: 2015-10-1117: 275 * Author: zhaoyingnan6 ** 78*9 _ construct ,__ destruct, c Redis, redis Getting Started Guide

You are busy...

1
 GetMethods (); 33 $ arMethods = objarray_to_array ($ arMethods); 34 // print_r ($ arMethods); 35 function objarray_to_array ($ obj) {36 $ ret = array (); 37 foreach ($ obj as $ key => $ value) {38 if (gettype ($ value) = "array" | gettype ($ value) = "object ") {39 $ ret [$ key] = objarray_to_array ($ value); 40} else {41 $ ret [$ key] = $ value; 42} 43} 44 return $ ret; 45} 46 $ I = 1; 47 foreach ($ arMethods as $ arVal) 48 echo $ arVal ['name'], ','; 49 50/******************************* Redis introduction ***** * ****************************/51 // Redis, A memory high-speed cache database with the data model key-value 52 // Redis can be persisted (that is, it will save the data from the hard disk) ensures data security 53 // Redis's rich data types: string, list, hash, set, sorted set 54 55 56/****************************** comparison between Redis and Memcached * *********************/57 // Redis not only supports simple key-value, it also provides storage of data structures such as list, set, and hash. Support master-slave (master-slave) mode application 59 // Redis supports data persistence, and the data in the memory can be stored on the hard disk in Spring Festival, when the instance is restarted or powered off, no data will be lost. 60 // The maximum 1 GB of a single Redis value is exceeded, memcached can only store 1 MB 61 62 63/****************************** Redis key operation **************************/64/** 65 * eixists key test specified whether the key of is 66 * del key1 key2 key3... delete the given key 67 * type key returns the value type of the given key 68 * keys pattern returns all keys matching the specified mode 69 * rename oldkeyname newkeyname change name 70 * dbsize return the number of keys of the current database 71 * expire key seconds set the expiration time for the key 72 * ttl key return the remaining expiration time of the key 73 * select db-index select database (0 -15) 74 * move key db-index move key from current database to specified database 75 * flushdb delete all keys in current database 76 * flushall delete all keys in all databases 77 **/78 79 80/******************************* string type operations in Redis * * *****************/81/**** 82 * set key value to string type value 83 * mset key1 value1 Key2 value2 keyN valueN sets the value of multiple keys at a time. 84 * mget key1 key2 keyN obtains the value of multiple keys at a time. 85 * incr key auto-incrementing the value of the key, the step value is 1, and the new value 86 * decr key is returned to perform the auto-subtraction operation on the key value. The step value is 1, and return the new value 87 * incrby key integer with incr, but the step value is the specified integer, and return the new value 88 * decrby key integer with decr, however, the step value is the specified integer, return the new value 89 * append key value to append the value 90 * substr key start end to the value corresponding to the specified key to return the value corresponding to the truncated key, including start and end positions, subscript starts from 0 91 **/92 93 94 /****************************** List-type operations in Redis *** * ******************/95 // the list type is a two-way linked list, push and pop operations are used to add or delete elements from the head or tail of the linked list. 96 // application scenario: obtain the information of the 10 users who have logged on to the newest. 97/*** lpush key value adds the value element to the header of the list corresponding to the key, returns the number of elements in the list 99 * rpush key value adds the value element to the end of the list corresponding to the key, returns the number of elements in the list. 100 * the rpop key deletes an element at the end of the list corresponding to the key, and returns the content of the element 101 * lpop key to delete an element in the header of the list corresponding to the key, and returns the content of this element 102 * llen key returns the number of elements in the list corresponding to the key. if it does not exist, it is 0, if it is not a list type, an error 103 * lrange key start end is returned, which indicates the elements in the specified range of the list corresponding to the key, including the start and end positions, subscript: starting from 0, 104 * ltrim key start key intercepts list, retain the elements in the specified range: 105 */106 107 108 /************************** * **********************************/109/set unordered set, the elements in each set are not repeated. they can contain up to 2 32 power elements (intersection, union, and difference set). 110 // application scenario: QQ friend recommendation, you and John's mutual friend 111/** 112 * sadd key member add a member element to the set corresponding to the key. 1 is returned successfully. if the element already exists, returns 0113 * sren key member1 memberN, which deletes a given element from the set corresponding to the key, 1114 * scard key is returned. the number of elements in the set corresponding to the key is 115 * smembers key is returned. all elements in the set corresponding to the key are returned, is an unordered 116 * sismember key member, which determines whether a member exists in the set corresponding to the key. If yes, 1 is returned, otherwise, for 0117 * smove key1 key2 member, move the member in the set corresponding to key1 to 118 * sinter key1 key2 keyN in the set corresponding to key2, and return the intersection of 119 of the set corresponding to all given keys. * sunion key1 key2 keyN returns the union set 120 * sdiff key1 key2 keyN of the set corresponding to all given keys. returns the difference set 121 */122 123 124/for the set corresponding to all given keys/ * **************************** sorted set operation in Redis *** * **************/125 // sorted set sorting set, different from the set, each element in each set is a combination of values and weights. 126 // application scenario: ranking 127/** 128 * zadd key score add elements to the set corresponding to the key, where the value is member, the weight is score129 * zrem key member. delete the specified element in the set corresponding to the key. member130 * zincrby key incr member increases the score weight of the member element in the set corresponding to the key by the incr range by 131. * zrank key member returns the rank subscript of the specified element member in the set corresponding to the key, rank by score to a large value, subscript 0 open 132 * zrevrank key member returns the rank subscript of the specified element member in the set corresponding to the key, ranking by score to a small value, subscript 0 open 133 * zrange key start end returns the value of the elements in the specified range in the set corresponding to the key. sort the score to a smaller value, and subscript 0 open, including the first and last 134 * zrevrange key start end, return the value of the elements in the specified range in the set corresponding to the key. the sorting score is as large as small as the subscript is 0, the number of elements in the set corresponding to the 135 * zcard key returned key is 136 * zscore key member returns the score value of the element whose value is set to member 137 * zremrangebyrank key min max deletes the elements ranked in the given range in the set corresponding to the key (sorted in descending order of score) 138 **/139 140 141/******************************* Redis data persistence ***********************************/142/ ** 143 * snapshot persistence 144 * This function is enabled by default, store all the data in Redis on the hard disk at one time. if there is a lot of data, it is not suitable to perform this operation frequently 145 * redis. conf146 * persistent snapshot backup frequency (high/low data modification frequency, high/low backup frequency) 147 * save 900 1 # if more than one key is modified within 900 seconds, a snapshot is initiated to save 148 * save 300 10 # if more than 10 keys are modified within 300 seconds, initiate a snapshot to save 149 * save 60 10000 # if more than 10000 keys are modified within 60 seconds, initiate a snapshot to save 150 * dbfilename dump. rdb # backup file name 151 * dir. /# backup file storage path 152 * manually initiate a snapshot persistence 153 * redis-cli-h 127.0.0.1-p 6379 bgsave # manually initiate a snapshot persistence 154 **/155 156 /* * 157 * append only file AOF persistence 158 * nature: back up each 'write' command executed by the user to a file. when restoring data, it actually executes the specific command 159 * which is not enabled by default, when it is enabled, the data in Redis is cleared. before using it, enable 160 * redis. conf161 * appendonly no #162 * appendfilename "appendonly is disabled by default. aof "# backup file name 163 * dir. /# backup file storage path 164 * when AOF persistence is enabled, use the corresponding configuration file to restart Redis165 * redis-server redis. conf166 * AOF persistent backup frequency 167 * redis. conf168 * # appendfsync always # backup is performed immediately upon receiving the write command, which is the safest, but the slowest, with an overhead of 169 * appendfsync everysec # force backup once per second, A compromise was made between performance and persistence. the default value is 170 * # appendfsync no #, which is fully dependent on the operating system. The performance is the best and persistence is not guaranteed, worst security 171 * optimized compression for AOF backup files 172 * for example, converting multiple incr commands into one set command 173 * redis-cli-h 127.0.0.1-p 6379 bgrewriteaof # optimized compression 174 **/

Why are you busy? Php 2/** 3 * Description: Redis 4 * Create date: 5 * Author: zhaoyingnan 6 **/7 8/* 9 _ construct ,__ destruct, 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.