redis

package module
v0.0.0-...-e52f545 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 License: MIT Imports: 7 Imported by: 2

README

go-local-redis

Redis server emulation for local GO storage.

At this point, method comments have been borrowed directly from redis.io/commands and methods may or may not correctly implement the intended API.

Installation
$ go get github.com/AnimationMentor/go-local-redis
Documentation

godoc.org/github.com/AnimationMentor/go-local-redis

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDumpFileName = "../redisServer.dump.json"
)

Functions

func BgSave

func BgSave(fileName string, complete chan bool) string

Save the DB in background. The OK code is immediately returned. Redis forks, the parent continues to serve the clients, the child saves the DB on disk then exits. A client my be able to check if the operation succeeded using the LASTSAVE command. Please refer to the persistence documentation for detailed information.

Return value Simple string reply

func Decr

func Decr(key string) string

Decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers. See INCR for extra information on increment/decrement operations.

Return value String reply: the value of key after the decrement

func Del

func Del(key ...string) (deletedCount int)

Removes the specified keys. A key is ignored if it does not exist.

Return value Integer reply: The number of keys that were removed.

func Exists

func Exists(key string) int

Returns if key exists.

Return value Integer reply, specifically: 1 if the key exists. 0 if the key does not exist.

func Get

func Get(key string) string

Get the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.

Return value Bulk string reply: the value of key, or nil when key does not exist.

func HDel

func HDel(key, field string) (existed int)

Removes the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored. If key does not exist, it is treated as an empty hash and this command returns 0.

Return value Integer reply: the number of fields that were removed from the hash, not including specified but non existing fields.

func HExists

func HExists(key, field string) (existed int)

Returns if field is an existing field in the hash stored at key.

Return value Integer reply, specifically: 1 if the hash contains field. 0 if the hash does not contain field, or key does not exist.

func HGet

func HGet(key, field string) string

Returns the value associated with field in the hash stored at key.

Return value Bulk string reply: the value associated with field, or nil when field is not present in the hash or key does not exist.

func HSet

func HSet(key, field, value string) (existed int)

Sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.

Return value Integer reply, specifically: 1 if field is a new field in the hash and value was set. 0 if field already exists in the hash and the value was updated.

func Hkeys

func Hkeys(key string) []string

Returns all field names in the hash stored at key.

Return value Array reply: list of fields in the hash, or an empty list when key does not exist.

func Hvals

func Hvals(key string) []string

Returns all values in the hash stored at key.

Return value Slice reply: list of values in the hash, or an empty list when key does not exist.

func Incr

func Incr(key string) string

Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer.

Return value String reply: the value of key after the increment

func InitDB

func InitDB(fileName string)

// Load any backup before doing anything else.

func Keys

func Keys(pattern string) (out []string)

Returns all keys matching pattern.

While the time complexity for this operation is O(N), the constant times are fairly low. For example, Redis running on an entry level laptop can scan a 1 million key database in 40 milliseconds. Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using sets. Supported glob-style patterns: h?llo matches hello, hallo and hxllo h*llo matches hllo and heeeello h[ae]llo matches hello and hallo, but not hillo Use \ to escape special characters if you want to match them verbatim.

Return value Array reply: list of keys matching pattern.

func Llen

func Llen(key string) int

Returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned. An error is returned when the value stored at key is not a list.

Return value Integer reply: the length of the list at key.

func Psubscribe

func Psubscribe(pattern ...string) consumer

Subscribes the client to the given patterns. Supported glob-style patterns: h?llo subscribes to hello, hallo and hxllo h*llo subscribes to hllo and heeeello h[ae]llo subscribes to hello and hallo, but not hillo Use \ to escape special characters if you want to match them verbatim.

func Rpush

func Rpush(key string, value ...string) int

Return value Integer reply: the length of the list after the push operation.

func Sadd

func Sadd(key string, member ...string) (additions int)

Add the specified members to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members. An error is returned when the value stored at key is not a set.

Return value Integer reply: the number of elements that were added to the set, not including all the elements already present into the set.

func Scard

func Scard(key string) (count int)

Returns all the members of the set value stored at key. This has the same effect as running SINTER with one argument key.

Return value Array reply: all elements of the set.

func Set

func Set(key, value string) string

Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.

func Setnx

func Setnx(key, value string) int

Set key to hold string value if key does not exist. In that case, it is equal to SET. When key already holds a value, no operation is performed. SETNX is short for "SET if N ot e X ists".

Return value Integer reply, specifically: 1 if the key was set 0 if the key was not set

func Smembers

func Smembers(key string) (out []string)

Returns all the members of the set value stored at key. This has the same effect as running SINTER with one argument key.

Return value Array reply: all elements of the set.

func Type

func Type(key string) string

Returns the string representation of the type of the value stored at key. The different types that can be returned are: string, list, set, zset and hash.

Return value Simple string reply: type of key, or none when key does not exist.

Types

type Hash

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

Hash is a concurrent safe string map

func Hgetall

func Hgetall(key string) Hash

Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value, so the length of the reply is twice the size of the hash.

Return value map[string]string reply: list of fields and their values stored in the hash, or an empty list when key does not exist.

func NewHash

func NewHash() Hash

NewHash creates a new Hash

func (Hash) Copy

func (h Hash) Copy() Hash

Copy keys and values to a new Hash

func (Hash) Delete

func (h Hash) Delete(key string)

Delete a key in the hash

func (Hash) Exists

func (h Hash) Exists(key string) bool

Exists returns whether a key exists in the hash

func (Hash) Get

func (h Hash) Get(key string) string

Get returns the value of a key in the map, or an empty string if it doesn't exist

func (Hash) GetExists

func (h Hash) GetExists(key string) (string, bool)

GetExists returns the value of a key in the map, and whether it existed.

func (Hash) Keys

func (h Hash) Keys() []string

Keys returns all keys in the hash

func (Hash) Set

func (h Hash) Set(key, value string)

Set a key to a value

func (Hash) Size

func (h Hash) Size() int

Size returns the number of items in the hash

func (Hash) ToMap

func (h Hash) ToMap() map[string]string

ToMap returns a copy of all data in the hash, as a map

func (Hash) Valid

func (h Hash) Valid() bool

Valid returns true if the Hash is a valid non-nil instance

func (Hash) Values

func (h Hash) Values() []string

Values returns all values in the hash

type List

type List []string

func Lrange

func Lrange(key string, start, stop int) (out List)

Return value Array reply: list of elements in the specified range.

type RedisSet

type RedisSet map[string]bool

Jump to

Keyboard shortcuts

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