zpop

Removes and returns the top value in a zset, with its score.

Returns Array - element and its score
Keys
  1. Sorted Set
Args None

Example

> zincrby scoreboard 1 bpo
"1"
> zincrby scoreboard 1 bpo
"2"
> zincrby scoreboard 1 tyson
"1"
> zincrby scoreboard 1 tyson
"2"
> zincrby scoreboard 1 tyson
"3"
> evalsha 196f7a1d80536678fc68084939fe2dc91ac29e67 1 scoreboard
1) "tyson"
2) "3"
> evalsha 196f7a1d80536678fc68084939fe2dc91ac29e67 1 scoreboard
1) "bpo"
2) "2"
> evalsha 196f7a1d80536678fc68084939fe2dc91ac29e67 1 scoreboard
(empty list or set)

Source

local result = redis.call('zrange', KEYS[1], -1, -1, "WITHSCORES")
if result then redis.call('zremrangebyrank', KEYS[1], -1, -1) end
return result

SHA

196f7a1d80536678fc68084939fe2dc91ac29e67

Explore Your Redis Memory Usage with an Interactive Map

RedisMonitor from RedisGreen shows you large keys, memory leaks, old keys, and other potential problems quickly. Try it now, no credit card required!

Last updated 08 Aug 2014.

← More scripts from the RedisGreen Library

License

All scripts on this site are in the public domain, unless otherwise noted, and are provided without warranty express or implied. RedisGreen make no claim for the effectiveness, safety, security or quality of the scripts contained within.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.