Skip to content

Commit

Permalink
luacheck, copyright bump
Browse files Browse the repository at this point in the history
  • Loading branch information
catwell committed Jan 2, 2016
1 parent 69b7758 commit cd34dd8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2012-2015 by Pierre Chapuis
Copyright (C) 2012-2016 by Pierre Chapuis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ fakeredis does not support multiple DBs. You should probably not use them anyway

## Copyright

Copyright (c) 2012-2015 Pierre Chapuis
Copyright (c) 2012-2016 Pierre Chapuis
47 changes: 25 additions & 22 deletions fakeredis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ local unpack = table.unpack or unpack

--- Bit operations

local ok,bit
if _VERSION == "Lua 5.3" then
bit = (load [[ return {
band = function(x, y) return x & y end,
bor = function(x, y) return x | y end,
bxor = function(x, y) return x ~ y end,
bnot = function(x) return ~x end,
rshift = function(x, n) return x >> n end,
lshift = function(x, n) return x << n end,
} ]])()
else
ok,bit = pcall(require,"bit")
if not ok then bit = bit32 end
local bit
do
if _VERSION == "Lua 5.3" then
bit = (load [[ return {
band = function(x, y) return x & y end,
bor = function(x, y) return x | y end,
bxor = function(x, y) return x ~ y end,
bnot = function(x) return ~x end,
rshift = function(x, n) return x >> n end,
lshift = function(x, n) return x << n end,
} ]])()
else
local ok
ok,bit = pcall(require,"bit")
if not ok then bit = bit32 end
end
end

assert(type(bit) == "table", "module for bitops not found")
Expand Down Expand Up @@ -80,16 +83,16 @@ local empty = function(self, k)
elseif t == "string" then
return not v[1]
elseif (t == "hash") or (t == "set") then
for _,_ in pairs(v) do return false end
if next(v) then return false end
return true
elseif t == "list" then
return v.head == v.tail
elseif t == "zset" then
if #v.list == 0 then
for _,_ in pairs(v.set) do error("incoherent") end
if next(v.set) then error("incoherent") end
return true
else
for _,_ in pairs(v.set) do return(false) end
if next(v.set) then return(false) end
error("incoherent")
end
else error("unsupported") end
Expand Down Expand Up @@ -500,15 +503,15 @@ local setnx = function(self, k, v)
end

local setrange = function(self, k, i, s)
local k, s = chkargs(2, k, s)
k, s = chkargs(2, k, s)
i = toint(i)
assert(i and (i >= 0))
local x = xgetw(self, k, "string")
local y = x[1] or ""
local ly, ls = #y, #s
if i > ly then -- zero padding
local t = {}
for i=1, i-ly do t[i] = "\0" end
for j=1, i-ly do t[j] = "\0" end
y = y .. table.concat(t) .. s
else
y = y:sub(1, i) .. s .. y:sub(i+ls+1, ly)
Expand Down Expand Up @@ -1044,7 +1047,7 @@ local srandmember = function(self, k, count)
r[#r+1] = table.remove(l, math.random(1, n-i))
end
else -- allow repetition
for i=1,-count do
for _=1,-count do
r[#r+1] = l[math.random(1, n)]
end
end
Expand Down Expand Up @@ -1162,7 +1165,7 @@ local _z_remove_range = function(x, i1, i2)
(i2 <= #l)
)
local ix, n = i1, i2-i1+1
for i=1,n do
for _=1,n do
x.set[l[ix].v] = nil
table.remove(l, ix)
end
Expand Down Expand Up @@ -1386,7 +1389,7 @@ local zinterstore = function(self, ...)
local x = xdefv("zset")
local aggregate
if params.aggregate == "sum" then
aggregate = function(x, y) return x+y end
aggregate = function(a, b) return a+b end
elseif params.aggregate == "min" then
aggregate = math.min
elseif params.aggregate == "max" then
Expand Down Expand Up @@ -1545,7 +1548,7 @@ local zunionstore = function(self, ...)
local default_score, aggregate
if params.aggregate == "sum" then
default_score = 0
aggregate = function(x, y) return x+y end
aggregate = function(a, b) return a+b end
elseif params.aggregate == "min" then
default_score = math.huge
aggregate = math.min
Expand Down
5 changes: 2 additions & 3 deletions fakeredis.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local TEST_REDIS_LUA = false
local unpack = table.unpack or unpack

local cwtest = require "cwtest"
local fakeredis = require "fakeredis"

local T = cwtest.new()

Expand Down Expand Up @@ -574,7 +573,7 @@ T:start("sets"); do
T:eq( #_x, 8 )
for i=1,#_x do T:eq( _cur[_x[i]], true ) end
local n
for t=1,10 do
for _=1,10 do
_cur = {A = true,B = true,C = true,D = true,E = true,F = true}
n = math.random(1,5)
_x = R:srandmember("S0",n)
Expand Down Expand Up @@ -786,7 +785,7 @@ T:start("keys"); do
for i=1,#_ks do _ks_set[_ks[i]] = true end
local _cur,_prev
local _founddiff,_notakey = false,false
for i=1,100 do
for _=1,100 do
_cur = R:randomkey()
if not _ks_set[_cur] then _notakey = true end
if _cur ~= _prev then _founddiff = true end
Expand Down

0 comments on commit cd34dd8

Please sign in to comment.