@@ -24,16 +24,17 @@ type AeroStore struct {
2424 WritePolicy * as.WritePolicy
2525 BasePolicy * as.BasePolicy
2626
27- c * as.Client
28- ns string
27+ c * as.Client
28+ ns string
29+ keyPrefix string
2930}
3031
3132// New creates a storage with the supplied namespace.
3233// Multiple hosts can be specified separated by ','.
3334// If no port is given on hosts, port 3000 is assumed.
3435// It is highly recommended to include a MaxSizeStore prior to this
3536// matching maximum storage size.
36- func New (namespace , hosts string ) (* AeroStore , error ) {
37+ func New (namespace , keyPrefix , hosts string ) (* AeroStore , error ) {
3738 var h []* as.Host
3839 for _ , hwp := range parseHosts (hosts , 3000 ) {
3940 h = append (h , as .NewHost (hwp .Name , hwp .Port ))
@@ -54,11 +55,19 @@ func New(namespace, hosts string) (*AeroStore, error) {
5455 BasePolicy : as .NewPolicy (),
5556 c : cl ,
5657 ns : namespace ,
58+ keyPrefix : keyPrefix ,
5759 }, nil
5860}
5961
62+ func (a * AeroStore ) prefix (key string ) string {
63+ if a .keyPrefix == "" {
64+ return key
65+ }
66+ return fmt .Sprintf ("%s_%s" , a .keyPrefix , key )
67+ }
68+
6069func (a * AeroStore ) Get (ctx context.Context , set , key string ) ([]byte , error ) {
61- k , err := as .NewKey (a .ns , set , key )
70+ k , err := as .NewKey (a .ns , set , a . prefix ( key ) )
6271 if err != nil {
6372 log .Error (ctx , err .Error ())
6473 return nil , err
@@ -88,7 +97,7 @@ func (a *AeroStore) Get(ctx context.Context, set, key string) ([]byte, error) {
8897}
8998
9099func (a * AeroStore ) Delete (ctx context.Context , set , key string ) error {
91- k , err := as .NewKey (a .ns , set , key )
100+ k , err := as .NewKey (a .ns , set , a . prefix ( key ) )
92101 if err != nil {
93102 log .Error (ctx , err .Error ())
94103 return err
@@ -101,7 +110,7 @@ func (a *AeroStore) Set(ctx context.Context, set, key string, val []byte) error
101110 if len (val ) > 1 << 20 {
102111 return blobstore .ErrBlobTooBig
103112 }
104- k , err := as .NewKey (a .ns , set , key )
113+ k , err := as .NewKey (a .ns , set , a . prefix ( key ) )
105114 if err != nil {
106115 return err
107116 }
0 commit comments