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/xuyu/goredis
redis client in golang
Go or Golang is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
Connect:
client, err := Dial()
client, err := Dial(&DialConfig{Address: "127.0.0.1:6379"})
client, err := DialURL("tcp://auth:password@127.0.0.1:6379/0?timeout=10s&maxidle=1")
Try a redis command is simple too, let's do GET/SET:
err := client.Set("key", "value", 0, 0, false, false)
value, err := client.Get("key")
Or you can execute a custom command with Redis.ExecuteCommand method:
reply, err := client.ExecuteCommand("SET", "key", "value")
err := reply.OKValue()
And then a Reply struct which represent the redis response data is defined:
type Reply struct {
Type int
Error string
Status string
Integer int64 // Support Redis 64bit integer
Bulk []byte // Support Redis Null Bulk Reply
Multi []*Reply
}
Reply.Type is defined as:
const (
ErrorReply = iota
StatusReply
IntegerReply
BulkReply
MultiReply
)
Reply struct has many useful methods:
func (rp *Reply) IntegerValue() (int64, error)
func (rp *Reply) BoolValue() (bool, error)
func (rp *Reply) StatusValue() (string, error)
func (rp *Reply) OKValue() error
func (rp *Reply) BytesValue() ([]byte, error)
func (rp *Reply) StringValue() (string, error)
func (rp *Reply) MultiValue() ([]*Reply, error)
func (rp *Reply) HashValue() (map[string]string, error)
func (rp *Reply) ListValue() ([]string, error)
func (rp *Reply) BytesArrayValue() ([][]byte, error)
func (rp *Reply) BoolArrayValue() ([]bool, error)
You can find more examples in test files.
normal test:
go test
coverage test:
go test -cover
coverage test with html result:
go test -coverprofile=cover.out
go tool cover -html=cover.out
Welcome to report issues :)
go test -test.run=none -test.bench="Benchmark.*"
At my virtualbox Ubuntu 13.04 with single CPU: Intel(R) Core(TM) i5-3450 CPU @ 3.10GHz, get result:
BenchmarkPing 50000 40100 ns/op
BenchmarkLPush 50000 34939 ns/op
BenchmarkLRange 50000 41420 ns/op
BenchmarkGet 50000 37948 ns/op
BenchmarkIncr 50000 44460 ns/op
BenchmarkSet 50000 41300 ns/op
Welcome to show your benchmark result :)
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.