Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
github.com/alicebob/miniredis
Pure Go Redis test server, used in Go unittests.
Sometimes you want to test code which uses Redis, without making it a full-blown
integration test.
Miniredis implements (parts of) the Redis server, to be used in unittests. It
enables a simple, cheap, in-memory, Redis replacement, with a real TCP interface. Think of it as the Redis version of net/http/httptest
.
It saves you from using mock code, and since the redis server lives in the test process you can query for values directly, without going through the server stack.
There are no dependencies on external binaries, so you can easily integrate it in automated build processes.
Added ZPopMin and ZPopMax
support for TIME (thanks @leon-barrett and @lirao) support for ZREVRANGEBYLEX fix for SINTER (thanks @robstein) updates for latest redis
Fixed nil Lua return value (#43)
Fixed using Lua with authenticated redis.
Changed redigo import path.
Minor cleanups. Miniredis now requires Go >= 1.9 (only for the tests. If you don't run the tests you can use an older Go version).
Lua changes: added cjson
library, and redis.sha1hex()
.
Added the EVAL
, EVALSHA
, and SCRIPT
commands. Uses a pure Go Lua interpreter. Please open an issue if there are problems with any Lua code.
Introduced StartAddr()
.
Internal cleanups. No changes in functionality.
2.0.0 improves TTLs to be time.Duration
values. .Expire()
is removed and
replaced by .TTL()
, which returns the TTL as a time.Duration
.
This should be the change needed to upgrade:
1.0:
m.Expire() == 4
2.0:
m.TTL() == 4 * time.Second
Furthermore, .SetTime()
is added to help with EXPIREAT
commands, and .FastForward()
is introduced to test keys expiration.
Implemented commands:
Since miniredis is intended to be used in unittests TTLs don't decrease
automatically. You can use TTL()
to get the TTL (as a time.Duration) of a
key. It will return 0 when no TTL is set.
m.FastForward(d)
can be used to decrement all TTLs. All TTLs which become <=
0 will be removed.
EXPIREAT and PEXPIREAT values will be converted to a duration. For that you can either set m.SetTime(t) to use that time as the base for the (P)EXPIREAT conversion, or don't call SetTime(), in which case time.Now() will be used.
SetTime() also sets the value returned by TIME, which defaults to time.Now(). It is not updated by FastForward, only by SetTime.
func TestSomething(t *testing.T) {
s, err := miniredis.Run()
if err != nil {
panic(err)
}
defer s.Close()
// Optionally set some keys your code expects:
s.Set("foo", "bar")
s.HSet("some", "other", "key")
// Run your code and see if it behaves.
// An example using the redigo library from "github.com/gomodule/redigo/redis":
c, err := redis.Dial("tcp", s.Addr())
_, err = c.Do("SET", "foo", "bar")
// Optionally check values in redis...
if got, err := s.Get("foo"); err != nil || got != "bar" {
t.Error("'foo' has the wrong value")
}
// ... or use a helper for that:
s.CheckGet(t, "foo", "bar")
// TTL and expiration:
s.Set("foo", "bar")
s.SetTTL("foo", 10*time.Second)
s.FastForward(11 * time.Second)
if s.Exists("foo") {
t.Fatal("'foo' should not have existed anymore")
}
}
Commands which will probably not be implemented:
Tests are run against Redis 5.0.3. The ./integration subdir compares miniredis against a real redis instance.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.