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/go-redis/redismock/v9
Provide mock test for redis query, Compatible with github.com/redis/go-redis/v9
Confirm that you are using redis.Client the version is github.com/redis/go-redis/v9
go get github.com/go-redis/redismock/v9
RedisClient
var ctx = context.TODO()
func NewsInfoForCache(redisDB *redis.Client, newsID int) (info string, err error) {
cacheKey := fmt.Sprintf("news_redis_cache_%d", newsID)
info, err = redisDB.Get(ctx, cacheKey).Result()
if err == redis.Nil {
// info, err = call api()
info = "test"
err = redisDB.Set(ctx, cacheKey, info, 30 * time.Minute).Err()
}
return
}
func TestNewsInfoForCache(t *testing.T) {
db, mock := redismock.NewClientMock()
newsID := 123456789
key := fmt.Sprintf("news_redis_cache_%d", newsID)
// mock ignoring `call api()`
mock.ExpectGet(key).RedisNil()
mock.Regexp().ExpectSet(key, `[a-z]+`, 30 * time.Minute).SetErr(errors.New("FAIL"))
_, err := NewsInfoForCache(db, newsID)
if err == nil || err.Error() != "FAIL" {
t.Error("wrong error")
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Error(err)
}
}
RedisCluster
clusterClient, clusterMock := redismock.NewClusterMock()
RedisClient:
Subscribe
/ PSubscribe
RedisCluster
Subscribe
/ PSubscribe
Pipeline
/ TxPipeline
Watch
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.