Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2219

Redis expire keys

$
0
0

I've some leaderboard stats for my players. Leaderboards have daily,weekly and monthly stats. So I using redis with its expire feature for leaderboards but there's a thing that I'd want to know. Is there any method that make key expired but if the key has expire already, it will not touch it. If the method doesn't exist, what is the more performance friendly method to check and set it? I've a lot of keys to check and set I don't want to slow the process.

Code

try (Jedis resource = redisManager.getResource()) {    Pipeline pipeline = resource.pipelined();    pipeline.multi();    for (PlayerData playerData : playerDataList) {        if (playerData.getKill() > 0) {            pipeline.zincrby("game.kill.total", playerData.getKill(), playerData.getId());            pipeline.zincrby("game.kill.monthly", playerData.getKill(), playerData.getId());            pipeline.zincrby("game.kill.weekly", playerData.getKill(), playerData.getId());        }    }    //if the key doesn't have expire date, add expire date to key.    pipeline.exec();}

Viewing all articles
Browse latest Browse all 2219


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>