Skip to content

feat: rueidishook#105

Merged
rueian merged 3 commits intomasterfrom
rueidishook
Oct 22, 2022
Merged

feat: rueidishook#105
rueian merged 3 commits intomasterfrom
rueidishook

Conversation

@rueian
Copy link
Copy Markdown
Collaborator

@rueian rueian commented Oct 22, 2022

Allow users to intercept rueidis.Client interface by wrapping it with another rueidishook.Hook interface:

package main

import (
	"context"
	"time"

	"github.com/rueian/rueidis"
	"github.com/rueian/rueidis/rueidishook"
)

type hook struct{}

func (h *hook) Do(client rueidis.Client, ctx context.Context, cmd rueidishook.Completed) (resp rueidis.RedisResult) {
	return client.Do(ctx, cmd)
}

func (h *hook) DoMulti(client rueidis.Client, ctx context.Context, multi ...rueidishook.Completed) (resps []rueidis.RedisResult) {
	return client.DoMulti(ctx, multi...)
}

func (h *hook) DoCache(client rueidis.Client, ctx context.Context, cmd rueidishook.Cacheable, ttl time.Duration) (resp rueidis.RedisResult) {
	return client.DoCache(ctx, cmd, ttl)
}

func (h *hook) DoMultiCache(client rueidis.Client, ctx context.Context, multi ...rueidis.CacheableTTL) (resps []rueidis.RedisResult) {
	return client.DoMultiCache(ctx, multi...)
}

func (h *hook) Receive(client rueidis.Client, ctx context.Context, subscribe rueidishook.Completed, fn func(msg rueidis.PubSubMessage)) (err error) {
	return client.Receive(ctx, subscribe, fn)
}

func main() {
	client, err := rueidis.NewClient(rueidis.ClientOption{InitAddress: []string{"127.0.0.1:6379"}})
	if err != nil {
		panic(err)
	}
	client = rueidishook.WithHook(client, &hook{})
	defer client.Close()
}

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 22, 2022

Codecov Report

Base: 96.44% // Head: 96.45% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (a1d73be) compared to base (58bbd5a).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #105      +/-   ##
==========================================
+ Coverage   96.44%   96.45%   +0.01%     
==========================================
  Files          35       36       +1     
  Lines       24838    24888      +50     
==========================================
+ Hits        23955    24006      +51     
+ Misses        763      762       -1     
  Partials      120      120              
Impacted Files Coverage Δ
rueidishook/hook.go 100.00% <100.00%> (ø)
rueidislock/lock.go 100.00% <0.00%> (+0.46%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rueian rueian merged commit 1c49fdd into master Oct 22, 2022
@rueian rueian deleted the rueidishook branch April 15, 2023 13:16
appleboy pushed a commit to appleboy/rueidis that referenced this pull request Oct 15, 2023
rueian added a commit that referenced this pull request Jan 26, 2026
* feat: add ability to get AZ from an INFO command

Signed-off-by: nickngsr <nick@logicallyus.com>

* docs: update Availability Affinity Routing to include hint about AZFromInfo

Signed-off-by: nickngsr <nick@logicallyus.com>

* fix: use raw string on infoAZ regex

Signed-off-by: nickngsr <nick@logicallyus.com>

* Update valkey.go

Signed-off-by: Rueian <rueiancsie@gmail.com>

---------

Signed-off-by: nickngsr <nick@logicallyus.com>
Signed-off-by: Rueian <rueiancsie@gmail.com>
Co-authored-by: Nick Rees <nick@logicallyus.com>
Co-authored-by: Rueian <rueiancsie@gmail.com>
Signed-off-by: Rueian <rueiancsie@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant