@@ -25,6 +25,7 @@ const (
25
25
keywordENS string = "ensDomain"
26
26
keywordFloorOS string = "floorOS"
27
27
keywordOSSlug string = "osslug"
28
+ keywordAddress string = "address"
28
29
keywordBlurSlug string = "blurslug"
29
30
keywordSalira string = "salira"
30
31
keyDelimiter string = ":"
@@ -94,10 +95,29 @@ func (r *Rueidica) StoreSalira(ctx context.Context, address common.Address, valu
94
95
}
95
96
96
97
// Slugs.
97
- func (r * Rueidica ) StoreOSSlug (ctx context.Context , address common.Address , slug string ) error {
98
- log .Debugf ("rueidica.StoreOSSlug | %+v -> %+v" , address .Hex (), slug )
98
+ func (r * Rueidica ) StoreOSSlugForAddress (ctx context.Context , address common.Address , slug string ) error {
99
+ log .Debugf ("rueidica.StoreOSSlugForAddress | %+v -> %+v" , address .Hex (), slug )
99
100
100
- return r .cacheName (ctx , address , slug , keyOSSlug , viper .GetDuration ("cache.slug_ttl" ))
101
+ return r .cacheName (ctx , address , slug , keyAddresToOSSlug , viper .GetDuration ("cache.slug_ttl" ))
102
+ }
103
+
104
+ func (r * Rueidica ) GetOSSlugForAddress (ctx context.Context , address common.Address ) (string , error ) {
105
+ log .Debugf ("rueidica.GetCachedENSName | %+v" , address )
106
+
107
+ return r .getCachedName (ctx , address , keyENS )
108
+ }
109
+
110
+ func (r * Rueidica ) StoreAddressForOSSlug (ctx context.Context , slug string , address common.Address ) error {
111
+ log .Debugf ("rueidica.StoreAddressForOSSlug | %+v -> %+v" , slug , address .Hex ())
112
+
113
+ return r .cacheAddressWithKey (ctx , keyOSSlugsToAddress (slug ), address , viper .GetDuration ("cache.slug_ttl" ))
114
+ // return r.cacheName(ctx, address, slug, keyOSSlugsToAddress, viper.GetDuration("cache.slug_ttl"))
115
+ }
116
+
117
+ func (r * Rueidica ) GetAddressForOSSlug (ctx context.Context , slug string ) (string , error ) {
118
+ log .Debugf ("rueidica.GetAddressForOSSlug | %+v" , slug )
119
+
120
+ return r .getCachedStringValueWithKey (ctx , keyOSSlugsToAddress (slug ))
101
121
}
102
122
103
123
func (r * Rueidica ) StoreBlurSlug (ctx context.Context , address common.Address , slug string ) error {
@@ -130,6 +150,27 @@ func (r *Rueidica) getCachedName(ctx context.Context, address common.Address, ke
130
150
return "" , errors .New ("value not found in cache" )
131
151
}
132
152
153
+ func (r * Rueidica ) getCachedStringValueWithKey (ctx context.Context , rKey string ) (string , error ) {
154
+ clientCacheTTL := viper .GetDuration ("cache.names_client_ttl" )
155
+
156
+ if r != nil {
157
+ cachedValue , err := r .DoCache (ctx , r .B ().Get ().Key (rKey ).Cache (), clientCacheTTL ).ToString ()
158
+
159
+ switch {
160
+ case err != nil && rueidis .IsRedisNil (err ):
161
+ gbl .Log .Debugf ("rueidis | no cachedValue in cache for %s" , rKey )
162
+ case err != nil :
163
+ gbl .Log .Errorf ("rueidis | error getting cached name: %s" , err )
164
+ default :
165
+ gbl .Log .Debugf ("rueidis | found name: %s -> %s" , rKey , cachedValue )
166
+ }
167
+
168
+ return cachedValue , err
169
+ }
170
+
171
+ return "" , errors .New ("value not found in cache" )
172
+ }
173
+
133
174
func (r * Rueidica ) getCachedNumber (ctx context.Context , address common.Address , keyFunc func (common.Address ) string ) (float64 , error ) {
134
175
clientCacheTTL := viper .GetDuration ("cache.names_client_ttl" )
135
176
@@ -173,6 +214,17 @@ func (r *Rueidica) cacheName(ctx context.Context, address common.Address, name s
173
214
return nil
174
215
}
175
216
217
+ func (r * Rueidica ) cacheAddressWithKey (ctx context.Context , rKey string , rValue common.Address , duration time.Duration ) error {
218
+ err := r .Do (ctx , r .B ().Set ().Key (rKey ).Value (rValue .Hex ()).ExSeconds (int64 (duration .Seconds ())).Build ()).Error ()
219
+ if err != nil {
220
+ gbl .Log .Errorf ("rueidis | error caching: %s ⇄ %s | %s" , rKey , rValue , err )
221
+
222
+ return err
223
+ }
224
+
225
+ return nil
226
+ }
227
+
176
228
//
177
229
// notifications lock
178
230
@@ -243,10 +295,14 @@ func keyFloorOS(address common.Address) string {
243
295
return fmt .Sprint (address .Hex (), keyDelimiter , keywordFloorOS )
244
296
}
245
297
246
- func keyOSSlug (address common.Address ) string {
298
+ func keyAddresToOSSlug (address common.Address ) string {
247
299
return fmt .Sprint (address .Hex (), keyDelimiter , keywordOSSlug )
248
300
}
249
301
302
+ func keyOSSlugsToAddress (slug string ) string {
303
+ return fmt .Sprint (slug , keyDelimiter , keywordAddress )
304
+ }
305
+
250
306
func keyBlurSlug (address common.Address ) string {
251
307
return fmt .Sprint (address .Hex (), keyDelimiter , keywordBlurSlug )
252
308
}
0 commit comments