-
Notifications
You must be signed in to change notification settings - Fork 337
Store reported piped stats to redis #2190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
45d012a
b763f23
ad12b0c
5d193d5
e475add
064be33
badf024
ecfbd0d
478ee0d
d7e89e0
f30a710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Copyright 2021 The PipeCD Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package rediscache | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| redigo "github.com/gomodule/redigo/redis" | ||
|
|
||
| "github.com/pipe-cd/pipe/pkg/cache" | ||
| "github.com/pipe-cd/pipe/pkg/redis" | ||
| ) | ||
|
|
||
| type RedisHashCache struct { | ||
| RedisCache | ||
| key string | ||
| } | ||
|
|
||
| func NewHashCache(redis redis.Redis, ttl time.Duration, key string) *RedisHashCache { | ||
| return &RedisHashCache{ | ||
| RedisCache: RedisCache{ | ||
| redis: redis, | ||
| }, | ||
| key: key, | ||
| } | ||
| } | ||
|
|
||
| func NewTTLHashCache(redis redis.Redis, ttl time.Duration, key string) *RedisHashCache { | ||
| return &RedisHashCache{ | ||
| RedisCache: RedisCache{ | ||
| redis: redis, | ||
| ttl: uint(ttl.Seconds()), | ||
| }, | ||
| key: key, | ||
| } | ||
| } | ||
|
|
||
| func (r *RedisHashCache) Put(k interface{}, v interface{}) error { | ||
| conn := r.redis.Get() | ||
| defer conn.Close() | ||
| _, err := conn.Do("HSET", r.key, k, v) | ||
| if r.ttl != 0 { | ||
| _, err = conn.Do("EXPIRE", r.key, r.ttl) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| func (r *RedisHashCache) GetAll() ([]interface{}, error) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who uses
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, this PR is focusing on storeing |
||
| conn := r.redis.Get() | ||
| defer conn.Close() | ||
| reply, err := redigo.StringMap(conn.Do("HGETALL", r.key)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can not use StringMap in this case. One more point is that instead of returning
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we adopt
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got it. Agree about that. 👍
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adopted returning |
||
| if err != nil { | ||
| if err == redigo.ErrNil { | ||
| return nil, cache.ErrNotFound | ||
| } | ||
| return nil, err | ||
| } | ||
| if len(reply) == 0 { | ||
| return nil, cache.ErrNotFound | ||
| } | ||
|
|
||
| out := make([]interface{}, 0, len(reply)) | ||
| for _, v := range reply { | ||
| out = append(out, v) | ||
| } | ||
| return out, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.