forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ErrClientConfiguration = errors.New("separate broker identities required")
|
||||
|
||||
// Clients parses configuration only; connecting/authenticating is deferred to
|
||||
// the native client. No credential or original parser error reaches diagnostics.
|
||||
func Clients(publishURL, consumeURL string) (*redis.Client, *redis.Client, error) {
|
||||
p, e := redis.ParseURL(publishURL)
|
||||
if e != nil {
|
||||
return nil, nil, ErrClientConfiguration
|
||||
}
|
||||
c, e := redis.ParseURL(consumeURL)
|
||||
if e != nil || p.Username == "" || c.Username == "" || p.Username == c.Username {
|
||||
return nil, nil, ErrClientConfiguration
|
||||
}
|
||||
for _, o := range []*redis.Options{p, c} {
|
||||
o.MaxRetries = -1
|
||||
o.DialTimeout = time.Second
|
||||
o.ReadTimeout = 2 * time.Second
|
||||
o.WriteTimeout = time.Second
|
||||
o.PoolSize = 2
|
||||
o.MaxActiveConns = 2
|
||||
o.MaxIdleConns = 1
|
||||
}
|
||||
return redis.NewClient(p), redis.NewClient(c), nil
|
||||
}
|
||||
Reference in New Issue
Block a user