Lua调用Redis

Redis 从2.6版本起开始支持 Lua 脚本 非脚本方式实现的访问限速 private boolean accessLimit(String ip, int limit, int time, Jedis jedis) { boolean result = true; String key = "rate.limit:" + ip; if (jedis.exists(key)) { long afterValue = jedis.incr(key); if (afterValue > limit) { result = false; } } else { Transaction transaction = jedis.multi(); transaction.incr(key); transaction.expire(key, time); transaction.exec(); } return result; } 使用Lua脚本实现的访问限速 Lua local key = "rate.limit:" .. KEYS[1] local limit = tonumber(ARGV[1]) local expire_time = ARGV[2] local is_exists = redis.call("EXISTS", key) if is_exists == 1 then if redis.call("INCR", key) > limit then return 0 else return 1 end else redis.call("SET", key, 1) redis.call("EXPIRE", key, expire_time) return 1 end Java ...

2017年3月14日 · 1 分钟 · Bug1024

Redis

特点 高性能Key-Value存储 丰富的数据结构:string、list、hash、set、zset、hypeloglog 支持数据过期:主动过期+惰性过期 支持多种LRU策略:volatile-lru、volatile-ttl 等 内存管理:tcmaloc、jemalloc 内存存储+磁盘持久化: rdb、aof 支持主从复制 单线程 配置 aof配置 ...

2017年1月5日 · 3 分钟 · Bug1024