npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@w5/redis_lua

v0.0.14

Published

[‼️]: ✏️README.mdt

Downloads

4

Readme

@w5/redis_lua

test/main.coffee :

#!/usr/bin/env coffee

> @w5/uridir
  @w5/read
  path > join
  @w5/redis_lua
  @w5/redis_lua/dot_bind.js

ROOT = uridir(import.meta)
LUA = read join ROOT,'redis.lua'

redis = {
  fbinR:=>
    new Uint8Array([])
  fnload:(lua)=>
    console.log lua
    return
  fstr:(args...)=>
    console.log 'fstr', ...args
    return
}


await RedisLua(redis).RedisLuaTest LUA

console.log '---'

BIND = DotBind redis

BIND.fstr.ipLimit()

await redis.ipLimit('key1','key2')('arg1','arg2')

output :

#!lua name=RedisLuaTest

local log = function(...)
  local li = {}
  for _, v in ipairs({ ... }) do
    table.insert(li, cjson.encode(v))
  end
  redis.log(redis.LOG_NOTICE, unpack(li))
end

local _byZid = function(key, score)
  score = tonumber(score)
  local r = redis.call("ZRANGEBYSCORE", key, score, score, "LIMIT", 0, 1)
  if r then
    return r[1]
  end
end

local intBin = function(n)
  local t = {}
  while n > 0 do
    local r = math.fmod(n, 256)
    table.insert(t, string.char(r))
    n = (n - r) / 256
  end
  return table.concat(t)
end

local binInt = function(str)
  local n = 0
  local base = 1
  for i = 1, #str do
    local c = str:sub(i, i)
    n = n + base * c:byte()
    base = base * 256
  end
  return n
end

local HSET = function(key, field, val)
  return redis.call("HSET", key, field, val)
end

local HGET = function(key, field)
  return redis.call("HGET", key, field)
end

local HINCRBY = function(key, field, increment)
  return redis.call("HINCRBY", key, field, increment)
end

local INCR = function(key)
  return redis.call("INCR", key)
end

local ZSCORE = function(key, member)
  local r = redis.call("ZSCORE", key, member)
  if r then
    return r.double
  end
end

local ZADD_XX = function(key, member, score)
  return redis.call("ZADD", key, "XX", score, member)
end

local ZADD = function(key, member, score)
  return redis.call("ZADD", key, score, member)
end

local ZINCRBY = function(key, member, increment)
  return redis.call("ZINCRBY", key, increment, member).double
end

local SISMEMBER = function(key, member)
  return redis.call("SISMEMBER", key, member)
end

local EXPIRE = function(key, seconds)
  return redis.call("EXPIRE", key, seconds)
end

local TTL = function(key)
  return redis.call("TTL", key)
end

local _zid = function(kv, k)
  local id = ZSCORE(kv, k)
  if nil == id then
    id = -ZINCRBY(kv, "", -1)
    ZADD(kv, k, id)
  end
  return id
end

redis.register_function('zid',function(keys, args)
  redis.setresp(3)
  return _zid(keys[1], args[1])
end)

redis.register_function{
function_name='zmax',
callback=function(keys, args)
  redis.setresp(3)
  local zset = keys[1]
  local max = redis.call("ZRANGE", zset, 0, 0, "REV", "WITHSCORES")
  if next(max) ~= nil then
    local min = args[1]
    if min ~= nil then
      min = tonumber(min)
      local max = max[1]
      if max[2].double > min then
        return max[1]
      end
    end
  end
end,
flags={'no-writes'}
}

redis.register_function('zero',function(keys, args)
  redis.setresp(3)
  local key = keys[1]
  local t = redis.call("ZRANGEBYSCORE", key, "(0", "+inf")
  local r = {}
  for i = 1, #t do
    table.insert(r, 0)
    table.insert(r, t[i])
  end
  redis.call("ZADD", key, unpack(r))
end)

local _ztouch = function(func, keys, args)
  local zset = keys[1]
  local key = args[1]
  local max = redis.call("ZRANGE", zset, 0, 0, "REV", "WITHSCORES")
  if next(max) == nil then
    max = 1
  else
    max = max[1]
    local val = max[2].double
    if max[1] == key and val ~= 0 then
      return
    end
    max = val + 1
  end
  func(zset, key, max)
end

redis.register_function('ztouch',function(keys, args)
  redis.setresp(3)
  _ztouch(ZADD, keys, args)
end)

redis.register_function('ztouchXx',function(keys, args)
  redis.setresp(3)
  _ztouch(ZADD_XX, keys, args)
end)

redis.register_function{
function_name='RedisLuaTestVer',
callback=function()
  redis.setresp(3)
  return "\188\0\180\11\100\122\172\50\199\66\224\34\38\70\84\131\139\84\230\175\183\85\160\149\120\156\137\85\99\119\50\166"
end,
flags={'no-writes'}
}
---
fstr ipLimit [ 'key1', 'key2' ] [ 'arg1', 'arg2' ]