---
title: "redis中统计sorted set的score的总和的lua脚本"
author: "李俊良"
date: "2014-06-05T10:08:41Z"
tags: []
categories: ["编程语言"]
slug: "redis-sorted-set-score-lua"
draft: false
lastmod: "2014-06-05T10:08:41Z"
id: 2076116
url: "https://frosh.iteye.com/blog/2076116"
---

```
eval "local res = 0;local totalCards;local i =0; totalCards = redis.call('zrangebyscore','inTimeCost','-inf','+inf','withscores');for i,v in ipairs(totalCards) do if i%2 == 0 then res = res + v; end; end;return res;" 0
```