redigo

package module
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2021 License: Apache-2.0 Imports: 4 Imported by: 1

README

go-gtc/redigo

Encapsulate gomodule/redigo, provide a method similar to the redis command.

Go Reference

Installation

go get tcw.im/gtc/redigo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTranClosed = errors.New("pipeline closed")

管道已经关闭(已经使用 Execute 提交)

Functions

func KPV added in v0.4.4

func KPV(key string, values []string) []interface{}

将key加入到v切片头部

Types

type DB

type DB struct {
	// key前缀
	Prefix string
	// contains filtered or unexported fields
}

DB 一个数据库连接结构

func New

func New(rawurl string) (c *DB, err error)

New 打开一个DB连接,rawurl是redis连接串

func (*DB) Del

func (c *DB) Del(key string) (bool, error)

Del 删除单个Key

func (*DB) Do

func (c *DB) Do(command string, args ...interface{}) (reply interface{}, err error)

Do 从连接池获取连接并执行命令

func (*DB) Expire

func (c *DB) Expire(key string, second uint64) (bool, error)

Expire 设置Key的过期时间,过期后将不可用,单位秒

func (*DB) Exsits

func (c *DB) Exsits(key string) (bool, error)

Exsits 判断是否有键

func (*DB) Get

func (c *DB) Get(key string) (string, error)

Get 获取数据

func (*DB) HDel added in v0.4.3

func (c *DB) HDel(name string, keys ...string) (uint64, error)

HDel 删除哈希表中的一个或多个指定字段

func (*DB) HExists

func (c *DB) HExists(name, key string) (bool, error)

HExists 判断哈希表中是否有某个Key

func (*DB) HGet

func (c *DB) HGet(name, key string) (string, error)

HGet 返回哈希表中指定字段的值

func (*DB) HGetAll

func (c *DB) HGetAll(name string) (map[string]string, error)

HGetAll 返回哈希表中所有的字段和值

func (*DB) HKeys added in v0.4.2

func (c *DB) HKeys(name string) ([]string, error)

HKeys 返回哈希表所有域的键

func (*DB) HLen

func (c *DB) HLen(name string) (uint64, error)

HLen 返回哈希表长度

func (*DB) HMSet

func (c *DB) HMSet(name string, hash map[string]string) (bool, error)

HMSet 为哈希表中的多个字段赋值

func (*DB) HSet

func (c *DB) HSet(name, key, value string) (uint64, error)

HSet 为哈希表中的字段赋值

func (*DB) HVals

func (c *DB) HVals(name string) ([]string, error)

HVals 返回哈希表所有域的值

func (*DB) Keys

func (c *DB) Keys(pattern string) ([]string, error)

Keys 查找所有符合给定模式 pattern 的 key

func (*DB) LLen

func (c *DB) LLen(key string) (uint64, error)

LLen 返回列表的长度

func (*DB) LPop

func (c *DB) LPop(key string) (string, error)

LPop 移除并返回列表的第一个元素

func (*DB) LRange

func (c *DB) LRange(key string, start, end int) ([]string, error)

LRange 返回列表中指定区间内的元素,区间以偏移量 START 和 END 指定

func (*DB) Ping

func (c *DB) Ping() (bool, error)

Ping 测试连接

func (*DB) Pipeline

func (c *DB) Pipeline() *TranCommand

Pipeline 开启事务,使用 Execute 方法提交事务。 使用示例:

t := instance.Pipeline()

t.Set/RPush/Del...(or use Send method)

t.Execute()

func (*DB) RPop

func (c *DB) RPop(key string) (string, error)

RPop 移除列表的最后一个元素

func (*DB) RPush

func (c *DB) RPush(key string, values ...string) (uint64, error)

RPush 将一个或多个值插入到列表的尾部(最右边)

func (*DB) SAdd

func (c *DB) SAdd(key string, members ...string) (uint64, error)

SAdd 将一个或多个成员元素加入到集合中,已经存在于集合的成员元素将被忽略

func (*DB) SCard

func (c *DB) SCard(key string) (uint64, error)

SCard 返回集合中元素的数量

func (*DB) SIsMember

func (c *DB) SIsMember(key, member string) (bool, error)

SIsMember 判断元素是否是集合的成员

func (*DB) SMembers

func (c *DB) SMembers(key string) ([]string, error)

SMembers 返回集合中的所有的成员

func (*DB) SRem

func (c *DB) SRem(key string, members ...string) (uint64, error)

SRem 移除集合中的一个或多个成员元素,不存在的成员元素会被忽略

func (*DB) Set

func (c *DB) Set(key, value string) (bool, error)

Set 添加数据

func (*DB) TTL

func (c *DB) TTL(key string) (uint64, error)

TTL 以秒为单位返回Key的剩余过期时间

func (*DB) Type

func (c *DB) Type(key string) (string, error)

Type 查看键类型

type TranCommand

type TranCommand struct {
	// contains filtered or unexported fields
}

TranCommand 表示事务管道。 执行流程是:由 `DB.Pipeline` 开启,通过 Send 缓冲命令,最后 Execute 发送。

func (*TranCommand) Del

func (t *TranCommand) Del(key string) error

Del 管道中的 Del

func (*TranCommand) Execute

func (t *TranCommand) Execute() ([]interface{}, error)

Execute 执行提交事务

func (*TranCommand) HDel added in v0.4.4

func (t *TranCommand) HDel(name string, keys ...string) error

HDel 管道中的 HDel

func (*TranCommand) HSet

func (t *TranCommand) HSet(name, key, value string) error

HSet 管道中的 HSet

func (*TranCommand) RPush

func (t *TranCommand) RPush(key string, values ...string) error

RPush 管道中的 RPush

func (*TranCommand) SAdd

func (t *TranCommand) SAdd(key string, members ...string) error

SAdd 管道中的 SAdd

func (*TranCommand) SRem

func (t *TranCommand) SRem(key string, members ...string) error

SRem 管道中的 SRem

func (*TranCommand) Send

func (t *TranCommand) Send(command string, args ...interface{}) error

Send 将命令写入客户端的输出缓冲区。

func (*TranCommand) Set

func (t *TranCommand) Set(key, value string) error

Set 管道中的 Set

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL