pabloem commented on a change in pull request #15721: URL: https://github.com/apache/beam/pull/15721#discussion_r732329970
########## File path: playground/backend/internal/cache/redis_cache.go ########## @@ -0,0 +1,145 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You 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 cache + +import ( + pb "beam.apache.org/playground/backend/internal/api" + "context" + "encoding/json" + "fmt" + "github.com/go-redis/redis/v8" + "github.com/google/uuid" + "google.golang.org/grpc/grpclog" + "time" +) + +const defaultExpirationTime = time.Minute * 15 + +type RedisCache struct { + redisClient *redis.Client +} + +// check connection to Redis +var ping = func(redisClient *redis.Client, ctx context.Context) (string, error) { + return redisClient.Ping(ctx).Result() +} + +// check if pipelineId exists as Redis key +var exists = func(redisClient *redis.Client, ctx context.Context, pipelineId uuid.UUID) (int64, error) { + return redisClient.Exists(ctx, pipelineId.String()).Result() +} + +// set expiration time for key +var expire = func(redisClient *redis.Client, ctx context.Context, key string, expTime time.Duration) (bool, error) { + return redisClient.Expire(ctx, key, expTime).Result() +} + +// put encoded value to {key}:{encoded subKey} structure +var hSet = func(redisClient *redis.Client, ctx context.Context, key string, subKeyMarsh, valueMarsh []byte) (int64, error) { + return redisClient.HSet(ctx, key, subKeyMarsh, valueMarsh).Result() +} + +// receive value from {key}:{subKey} structure +var hGet = func(redisClient *redis.Client, ctx context.Context, key, subKey string) (string, error) { + return redisClient.HGet(ctx, key, subKey).Result() +} + +// newRedisCache returns Redis implementation of Cache interface. +// In case of problem with connection to Redis returns error. +func newRedisCache(ctx context.Context, addr string) (*RedisCache, error) { Review comment: yes, let's keep it private since the public constructor is above : ) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
