-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from brzyangg/master
add redis pipeline
- Loading branch information
Showing
16 changed files
with
1,201 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package redis | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_instanceConfFromString(t *testing.T) { | ||
type args struct { | ||
s string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantConf *InstanceConf | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "test no prefix key", | ||
args: args{ | ||
s: "default-base/test-e-false", | ||
}, | ||
wantConf: &InstanceConf{ | ||
Group: "default", | ||
Namespace: "base/test", | ||
Wrapper: "e", | ||
NoFixKey: false, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotConf, err := instanceConfFromString(tt.args.s) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("instanceConfFromString() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(gotConf, tt.wantConf) { | ||
t.Errorf("instanceConfFromString() gotConf = %v, want %v", gotConf, tt.wantConf) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package redis | ||
|
||
// redis Client options | ||
type options struct { | ||
// fix key #{namespace.wrapper.key} | ||
wrapper string | ||
// if true no fix key | ||
noFixKey bool | ||
// if true key => #{namespace.wrapper.key} else key => #{namespace.key} | ||
useWrapper bool | ||
} | ||
|
||
type Option interface { | ||
apply(*options) | ||
} | ||
|
||
type wrapperOption string | ||
|
||
func (c wrapperOption) apply(opts *options) { | ||
opts.wrapper = string(c) | ||
} | ||
|
||
func WithWrapper(w string) Option { | ||
return wrapperOption(w) | ||
} | ||
|
||
type noFixKeyOption bool | ||
|
||
func (c noFixKeyOption) apply(opts *options) { | ||
opts.noFixKey = bool(c) | ||
} | ||
|
||
func WithNoFixKey(n bool) Option { | ||
return noFixKeyOption(n) | ||
} | ||
|
||
type useWrapperOption bool | ||
|
||
func (c useWrapperOption) apply(opts *options) { | ||
opts.useWrapper = bool(c) | ||
} | ||
|
||
func WithUseWrapper(n bool) Option { | ||
return useWrapperOption(n) | ||
} |
Oops, something went wrong.