In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to implement Redis List operation in php, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
List action
//insert a value from the list header.$ ret = $redis->lPush ('city ', ' guangzhou');//Insert a value from the end of the list.$ ret = $redis->rPush ('city ', ' guangzhou');//Gets the elements in the specified interval of the list. 0 indicates the first element of the list,-1 indicates the last element, and-2 indicates the penultimate element.$ ret = $redis->lrange ('city ', 0, -1);//View all elements of the queue//Insert one into the head of an existing list, invalid if the list does not exist.$ ret = $redis->lPushx ('city ', ' hangzhou');//Insert one or more values into the end of an existing list, invalid if the list does not exist.$ ret = $redis->rPushx ('city ', ' hangzhou');//removes and returns the first element of the list, or false if the key does not exist or is not a list.$ ret = $redis->lPop ('city ');//removes and returns the last element of the list, or false if key does not exist or is not a list.$ ret = $redis->rPop ('city ');//Remove and get the first element of the list. If the list has no elements, it blocks the list until the wait times out or pop-up elements are found.// Parameters: key, timeout time (in seconds)//Return value: [0=>key,1=>value], timeout returns []$ret = $redis->blPop ('city ', 10);//Remove and get the last element of the list. If the list has no elements, it blocks the list until the wait times out or pop-up elements are found.// Parameters: key, timeout (in seconds)//Return value: [0=>key,1=>value], timeout returns []$ret = $redis->brPop ('city ', 10);//Remove the last element in the list, insert it into the head of another list, and return this element. Returns false if the source list has no elements.$ ret = $redis->rpoplpush ('city ', ' city2');//removes the last element in the list, inserts it into the head of another list, and returns this element. If the list has no elements, it blocks the list until the wait times out or pop-up elements are found.// Parameters: source list, destination list, timeout time (in seconds)//timeout returns false$ret = $redis->brpoplpush ('city ', 'city 2', 10);//returns list length.$ ret = $redis->lLen ('city ');//Get elements from list by index. Returns false if the index is outside the list.$ ret = $redis->lindex ('city ', 0);//Sets the value of an element in the list by index. Returns false if the index is out of range, or if an lset operation is performed on an empty list.$ ret = $redis->lSet ('city ', 2, ' changsha');//Insert an element before or after the specified element in the list. If the specified element is not in the list, or if the list does not exist, no action is performed.// Parameters: list key, Redis::AFTER or Redis::BEFORE, base element, insert element//Return value: insert succeeds Returns the number of list elements inserted, if base element does not exist returns-1, if key does not exist returns 0, if key is not a list returns false.$ ret = $redis->lInsert ('city ', Redis::AFTER, ' changsha','nanjing');//Remove elements in the list equal to parameter value based on the value of the third parameter count.// count > 0 : Search from head to tail, remove elements equal to value, count.// count
< 0 : 从表尾开始向表头搜索,移除与value相等的元素,数量为count的绝对值。//count = 0 : 移除表中所有与value相等的值。//返回实际删除元素个数$ret = $redis->lrem ('city ', ' guangzhou',-2);//prunes a list, keeping only elements in the specified interval and deleting all other elements. Success returns true.$ ret = $redis->ltrim ('city ', 1, 4); About "php how to achieve Redis List operation" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 218
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.