catwell / fakeredis Goto Github PK
View Code? Open in Web Editor NEWA Redis mock for Lua with the same interface as redis-lua.
License: MIT License
A Redis mock for Lua with the same interface as redis-lua.
License: MIT License
When needing to sleep, see if the "sleep" key is set on the client. If so, use it as the sleep function. Use the one from luasocket by default.
It is nice to have redis-lua API built in, but there are other Redis client libraries with different semantics (for example, lua-resty-redis, my lua-hiredis etc.).
Wrapping redis-lua API in a proxy code to support other APIs would be weird and quirky. Please add a low-level API so anyone will be able to code their API on top of that.
In the Redis documentation we can see that those commands refuse to work with values that do not fit in 64 bits.
In Lua (at least until 5.3), we should actually limit it to what can be represented with integer precision in a number, i.e. any -2^53<n<2^53
.
Namely -inf
and +inf
, e.g:
R:zrangebyscore("myzset","(1","+inf")
On Redis side, it relies on
strtod(3)
capabilities. See: zslParseRange .
Currently data is stored directly in the top-level object. This causes problems and should be changed asap.
For instance:
lrange("foo","0","-1")
@catwell ,
Your fakeredis library is exactly what I was looking for.
A nice local Redis 100% in Lua able to run without remote Server.
I just would like to inform you that I am doing persistence on the self.data database table.
Therefore I noticed a small issue in zadd command, when the key was already stored at the database previously.
The solution is very simple, somehow you forgot to add the .s at _z_update() function.
Without the .s you are comparing 2 tables and this generates a Lua error.
With just this simple change it works perfectly well !!!
local _z_update = function(x, p)
local l = x.list
local found = _z_remove(x, p.v)
local ix = nil
for i=1,#l do
..if l[i].s > p.s then -- @@ Filgs: the .s was missing in the original library
....ix = i; break
..end
end
if not ix then ix = #l+1 end
_z_insert(x, ix, p)
return found
end
Very nice job !
@Filgs
HMSET and maybe other commands only accept the table-based way of passing arguments, i.e. this works:
R:hmset("key", {foo = "bar", spam = "eggs"})
but not this:
R:hmset("key", "foo", "bar", "spam", "eggs")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.