github.com/wangyougui/gf/v2@v2.6.5/database/gredis/gredis_redis_group_generic.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package gredis 8 9 import ( 10 "context" 11 "time" 12 13 "github.com/wangyougui/gf/v2/container/gvar" 14 ) 15 16 // IGroupGeneric manages generic redis operations. 17 // Implements see redis.GroupGeneric. 18 type IGroupGeneric interface { 19 Copy(ctx context.Context, source, destination string, option ...CopyOption) (int64, error) 20 Exists(ctx context.Context, keys ...string) (int64, error) 21 Type(ctx context.Context, key string) (string, error) 22 Unlink(ctx context.Context, keys ...string) (int64, error) 23 Rename(ctx context.Context, key, newKey string) error 24 RenameNX(ctx context.Context, key, newKey string) (int64, error) 25 Move(ctx context.Context, key string, db int) (int64, error) 26 Del(ctx context.Context, keys ...string) (int64, error) 27 RandomKey(ctx context.Context) (string, error) 28 DBSize(ctx context.Context) (int64, error) 29 Keys(ctx context.Context, pattern string) ([]string, error) 30 FlushDB(ctx context.Context, option ...FlushOp) error 31 FlushAll(ctx context.Context, option ...FlushOp) error 32 Expire(ctx context.Context, key string, seconds int64, option ...ExpireOption) (int64, error) 33 ExpireAt(ctx context.Context, key string, time time.Time, option ...ExpireOption) (int64, error) 34 ExpireTime(ctx context.Context, key string) (*gvar.Var, error) 35 TTL(ctx context.Context, key string) (int64, error) 36 Persist(ctx context.Context, key string) (int64, error) 37 PExpire(ctx context.Context, key string, milliseconds int64, option ...ExpireOption) (int64, error) 38 PExpireAt(ctx context.Context, key string, time time.Time, option ...ExpireOption) (int64, error) 39 PExpireTime(ctx context.Context, key string) (*gvar.Var, error) 40 PTTL(ctx context.Context, key string) (int64, error) 41 } 42 43 // CopyOption provides options for function Copy. 44 type CopyOption struct { 45 DB int // DB option allows specifying an alternative logical database index for the destination key. 46 REPLACE bool // REPLACE option removes the destination key before copying the value to it. 47 } 48 49 type FlushOp string 50 51 const ( 52 FlushAsync FlushOp = "ASYNC" // ASYNC: flushes the databases asynchronously 53 FlushSync FlushOp = "SYNC" // SYNC: flushes the databases synchronously 54 ) 55 56 // ExpireOption provides options for function Expire. 57 type ExpireOption struct { 58 NX bool // NX -- Set expiry only when the key has no expiry 59 XX bool // XX -- Set expiry only when the key has an existing expiry 60 GT bool // GT -- Set expiry only when the new expiry is greater than current one 61 LT bool // LT -- Set expiry only when the new expiry is less than current one 62 }