redis中有这样一个数组:
array =[1,2,3,4,5,6,7,8,9,0]
请问redis有没有这样一个方法实现如下:
functionName(array,0,5)
这个方法返回[1,2,3,4,5,6]
同时原来的array的结果变成[7,8,9,0]
请问redis中有这样的方法吗?
没有的话,最简单的实现是怎样的呢?
PHP中文网2017-04-24 09:14:14
There is no similar method, it can be implemented like this:
lorange 0, 5 to get the first 6 elements
ltrim 7, -1 deletes the elements before the 7th element
There are also some boundary conditions, please check the documentation.
黄舟2017-04-24 09:14:14
No. In redis, only pop instructions perform deletion operations while taking values. The RANGE type operation can only take data within a specified range and cannot delete it at the same time.
Wouldn’t this need be solved by writing a few lines of PHP code? There is no need to be so entangled, right?