Ai
1 Star 0 Fork 1

go-spring2/spring-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ops_key.go 5.75 KB
一键复制 编辑 原始数据 按行查看 历史
kzhu 提交于 2025-04-03 19:08 +08:00 . first commit
/*
* Copyright 2012-2019 the original author or 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
*
* https://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 redis
import (
"context"
)
// Del https://redis.io/commands/del
// Command: DEL key [key ...]
// Integer reply: The number of keys that were removed.
func (c *Client) Del(ctx context.Context, keys ...string) (int64, error) {
args := []interface{}{"DEL"}
for _, key := range keys {
args = append(args, key)
}
return c.Int(ctx, args...)
}
// Dump https://redis.io/commands/dump
// Command: DUMP key
// Bulk string reply: the serialized value.
// If key does not exist a nil bulk reply is returned.
func (c *Client) Dump(ctx context.Context, key string) (string, error) {
args := []interface{}{"DUMP", key}
return c.String(ctx, args...)
}
// Exists https://redis.io/commands/exists
// Command: EXISTS key [key ...]
// Integer reply: The number of keys existing among the
// ones specified as arguments. Keys mentioned multiple
// times and existing are counted multiple times.
func (c *Client) Exists(ctx context.Context, keys ...string) (int64, error) {
args := []interface{}{"EXISTS"}
for _, key := range keys {
args = append(args, key)
}
return c.Int(ctx, args...)
}
// Expire https://redis.io/commands/expire
// Command: EXPIRE key seconds [NX|XX|GT|LT]
// Integer reply: 1 if the timeout was set, 0 if the timeout was not set.
func (c *Client) Expire(ctx context.Context, key string, expire int64, args ...interface{}) (int64, error) {
args = append([]interface{}{"EXPIRE", key, expire}, args...)
return c.Int(ctx, args...)
}
// ExpireAt https://redis.io/commands/expireat
// Command: EXPIREAT key timestamp [NX|XX|GT|LT]
// Integer reply: 1 if the timeout was set, 0 if the timeout was not set.
func (c *Client) ExpireAt(ctx context.Context, key string, expireAt int64, args ...interface{}) (int64, error) {
args = append([]interface{}{"EXPIREAT", key, expireAt}, args...)
return c.Int(ctx, args...)
}
// Keys https://redis.io/commands/keys
// Command: KEYS pattern
// Array reply: list of keys matching pattern.
func (c *Client) Keys(ctx context.Context, pattern string) ([]string, error) {
args := []interface{}{"KEYS", pattern}
return c.StringSlice(ctx, args...)
}
// Persist https://redis.io/commands/persist
// Command: PERSIST key
// Integer reply: 1 if the timeout was removed,
// 0 if key does not exist or does not have an associated timeout.
func (c *Client) Persist(ctx context.Context, key string) (int64, error) {
args := []interface{}{"PERSIST", key}
return c.Int(ctx, args...)
}
// PExpire https://redis.io/commands/pexpire
// Command: PEXPIRE key milliseconds [NX|XX|GT|LT]
// Integer reply: 1 if the timeout was set, 0 if the timeout was not set.
func (c *Client) PExpire(ctx context.Context, key string, expire int64, args ...interface{}) (int64, error) {
args = append([]interface{}{"PEXPIRE", key, expire}, args...)
return c.Int(ctx, args...)
}
// PExpireAt https://redis.io/commands/pexpireat
// Command: PEXPIREAT key milliseconds-timestamp [NX|XX|GT|LT]
// Integer reply: 1 if the timeout was set, 0 if the timeout was not set.
func (c *Client) PExpireAt(ctx context.Context, key string, expireAt int64, args ...interface{}) (int64, error) {
args = append([]interface{}{"PEXPIREAT", key, expireAt}, args...)
return c.Int(ctx, args...)
}
// PTTL https://redis.io/commands/pttl
// Command: PTTL key
// Integer reply: TTL in milliseconds, -1 if the key exists
// but has no associated expire, -2 if the key does not exist.
func (c *Client) PTTL(ctx context.Context, key string) (int64, error) {
args := []interface{}{"PTTL", key}
return c.Int(ctx, args...)
}
// RandomKey https://redis.io/commands/randomkey
// Command: RANDOMKEY
// Bulk string reply: the random key, or nil when the database is empty.
func (c *Client) RandomKey(ctx context.Context) (string, error) {
return c.String(ctx, "RANDOMKEY")
}
// Rename https://redis.io/commands/rename
// Command: RENAME key newkey
// Simple string reply.
func (c *Client) Rename(ctx context.Context, key, newKey string) (string, error) {
args := []interface{}{"RENAME", key, newKey}
return c.String(ctx, args...)
}
// RenameNX https://redis.io/commands/renamenx
// Command: RENAMENX key newkey
// Integer reply: 1 if key was renamed to newKey, 0 if newKey already exists.
func (c *Client) RenameNX(ctx context.Context, key, newKey string) (int64, error) {
args := []interface{}{"RENAMENX", key, newKey}
return c.Int(ctx, args...)
}
// Touch https://redis.io/commands/touch
// Command: TOUCH key [key ...]
// Integer reply: The number of keys that were touched.
func (c *Client) Touch(ctx context.Context, keys ...string) (int64, error) {
args := []interface{}{"TOUCH"}
for _, key := range keys {
args = append(args, key)
}
return c.Int(ctx, args...)
}
// TTL https://redis.io/commands/ttl
// Command: TTL key
// Integer reply: TTL in seconds, -1 if the key exists
// but has no associated expire, -2 if the key does not exist.
func (c *Client) TTL(ctx context.Context, key string) (int64, error) {
args := []interface{}{"TTL", key}
return c.Int(ctx, args...)
}
// Type https://redis.io/commands/type
// Command: TYPE key
// Simple string reply: type of key, or none when key does not exist.
func (c *Client) Type(ctx context.Context, key string) (string, error) {
args := []interface{}{"TYPE", key}
return c.String(ctx, args...)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go-spring2/spring-core.git
git@gitee.com:go-spring2/spring-core.git
go-spring2
spring-core
spring-core
v1.1.3

搜索帮助