redis

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RdPool

type RdPool struct {
	Name string
	// contains filtered or unexported fields
}

func GetRedisByName

func GetRedisByName(name string) *RdPool

GetRedisByName 不处理错误, 连写方式

func GetRedisPool

func GetRedisPool(name string) (*RdPool, error)

GetRedisPool 每次用前先获得redis pool的实例

func NewRedis

func NewRedis(name string, addr string, passwd string) *RdPool

NewRedis 生成新的redis实例并放入Pool中

func (*RdPool) ClosePool

func (c *RdPool) ClosePool() error

ClosePool 关闭连接池

func (*RdPool) Del

func (c *RdPool) Del(key string) (int64, error)

Del redis> SET key1 "Hello" "OK" redis> SET key2 "World" "OK" redis> DEL key1 key2 key3 (integer) 2

func (*RdPool) Do

func (c *RdPool) Do(commandName string, args ...interface{}) (interface{}, error)

Do 通用接口

func (*RdPool) Expired

func (c *RdPool) Expired(key string, seconds int) (int64, error)

Expired redis> SET mykey "Hello" "OK" redis> EXPIRE mykey 10 (integer) 1 redis> TTL mykey (integer) 10

func (*RdPool) Get

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

Get redis> GET mykey "Hello" redis>

func (*RdPool) HDel

func (c *RdPool) HDel(key string, fields ...string) (int64, error)

HDel redis> HSET myhash field1 "foo" (integer) 1 redis> HDEL myhash field1 (integer) 1

func (*RdPool) HGet

func (c *RdPool) HGet(key string, subKey string) (string, error)

HGet redis> HGET myhash field1 "foo"

func (*RdPool) HGetAll

func (c *RdPool) HGetAll(key string) (map[string]string, error)

HGetAll redis> HSET myhash field1 "Hello" (integer) 1 redis> HSET myhash field2 "World" (integer) 1 redis> HGETALL myhash 1) "field1" 2) "Hello" 3) "field2" 4) "World"

func (*RdPool) HMGet

func (c *RdPool) HMGet(key string, values ...string) ([]string, error)

HMGet redis> HSET myhash field1 "Hello" (integer) 1 redis> HSET myhash field2 "World" (integer) 1 redis> HMGET myhash field1 field2 nofield 1) "Hello" 2) "World" 3) (nil)

func (*RdPool) HMSet

func (c *RdPool) HMSet(key string, kv map[string]string) (string, error)

HMSet redis> HMSET myhash field1 "Hello" field2 "World" "OK" redis> HGET myhash field1 "Hello" redis> HGET myhash field2 "World"

func (*RdPool) HSet

func (c *RdPool) HSet(key string, subKey string, val string) (int64, error)

HSet redis> HSET myhash field1 "foo" (integer) 1

func (*RdPool) HSetEX

func (c *RdPool) HSetEX(key, field string, value interface{}, expire int) (int64, error)

HSetEX 127.0.0.1:6379> hset chair aaa 111 (integer) 1 127.0.0.1:6379> expire chair 10 (integer) 1 127.0.0.1:6379> ttl chair (integer) 8

func (*RdPool) Increment

func (c *RdPool) Increment(key string) (int64, error)

Increment redis> SET mykey "10" "OK" redis> INCR mykey (integer) 11 redis> GET mykey "11"

func (*RdPool) LIndex

func (c *RdPool) LIndex(key string, index int) (string, error)

LIndex redis> LPUSH mylist "World" (integer) 1 redis> LPUSH mylist "Hello" (integer) 2 redis> LINDEX mylist 0 "Hello" redis> LINDEX mylist -1 "World" redis> LINDEX mylist 3 (nil)

func (*RdPool) LLen

func (c *RdPool) LLen(key string) (int64, error)

LLen redis> LPUSH mylist "World" (integer) 1 redis> LPUSH mylist "Hello" (integer) 2 redis> LLEN mylist (integer) 2 redis>

func (*RdPool) LPop

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

LPop redis> RPUSH mylist "one" "two" "three" "four" "five" (integer) 5 redis> LPOP mylist "one" redis> LPOP mylist 2 1) "two" 2) "three" redis> LRANGE mylist 0 -1 1) "four" 2) "five"

func (*RdPool) LPush

func (c *RdPool) LPush(key string, values ...interface{}) (int64, error)

LPush redis> LPUSH mylist "world" (integer) 1 redis> LPUSH mylist "hello" (integer) 2 redis> LRANGE mylist 0 -1 1) "hello" 2) "world"

func (*RdPool) LPushX

func (c *RdPool) LPushX(key string, values ...interface{}) (int64, error)

LPushX redis> LPUSH mylist "World" (integer) 1 redis> LPUSHX mylist "Hello" (integer) 2 redis> LPUSHX myotherlist "Hello" (integer) 0 redis> LRANGE mylist 0 -1 1) "Hello" 2) "World" redis> LRANGE myotherlist 0 -1 (empty array)

func (*RdPool) LRange

func (c *RdPool) LRange(key string, start, stop int64) ([]string, error)

func (*RdPool) LRem

func (c *RdPool) LRem(key string, count int, value string) (int64, error)

LRem redis> RPUSH mylist "hello" (integer) 1 redis> RPUSH mylist "hello" (integer) 2 redis> RPUSH mylist "foo" (integer) 3 redis> RPUSH mylist "hello" (integer) 4 redis> LREM mylist -2 "hello" (integer) 2 redis> LRANGE mylist 0 -1 1) "hello" 2) "foo"

func (*RdPool) LSet

func (c *RdPool) LSet(key, value string, index int) (int64, error)

LSet redis> RPUSH mylist "one" (integer) 1 redis> RPUSH mylist "two" (integer) 2 redis> RPUSH mylist "three" (integer) 3 redis> LSET mylist 0 "four" "OK" redis> LSET mylist -2 "five" "OK" redis> LRANGE mylist 0 -1 1) "four" 2) "five" 3) "three"

func (*RdPool) LTrim

func (c *RdPool) LTrim(key string, start, stop int) (string, error)

LTrim redis> RPUSH mylist "one" (integer) 1 redis> RPUSH mylist "two" (integer) 2 redis> RPUSH mylist "three" (integer) 3 redis> LTRIM mylist 1 -1 "OK" redis> LRANGE mylist 0 -1 1) "two" 2) "three"

func (*RdPool) MGet

func (c *RdPool) MGet(keys ...string) ([]string, error)

func (*RdPool) MSet

func (c *RdPool) MSet(pairs ...interface{}) (string, error)

MSet redis> MSET key1 "Hello" key2 "World"

func (*RdPool) Ping

func (c *RdPool) Ping() (string, error)

Ping redis> PING "PONG"

func (*RdPool) Set

func (c *RdPool) Set(key string, val string) (string, error)

Set redis> SET mykey "Hello" "OK"

func (*RdPool) SetEX

func (c *RdPool) SetEX(key string, value interface{}, expire int) (string, error)

SetEx redis> SETEX mykey 10 "Hello" "OK" redis> TTL mykey (integer) 10 redis> GET mykey "Hello" redis>

func (*RdPool) SetNX

func (c *RdPool) SetNX(key string, value interface{}, expire int) (int64, error)

SetNX redis> SETNX mykey "Hello" (integer) 1 redis> SETNX mykey "World" (integer) 0 redis> GET mykey "Hello"

func (*RdPool) SilenceGet

func (c *RdPool) SilenceGet(key string) string

SilenceGet 不会返回错误, 只返回空

func (*RdPool) Ttl

func (c *RdPool) Ttl(key string) (int64, error)

Jump to

Keyboard shortcuts

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