redis

package
v0.0.0-...-31376d9 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package redis implements a redis client for k6.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents the Client constructor (i.e. `new redis.Client()`) and returns a new Redis client object.

func (*Client) Decr

func (c *Client) Decr(key string) *goja.Promise

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

func (*Client) DecrBy

func (c *Client) DecrBy(key string, decrement int64) *goja.Promise

DecrBy decrements the number stored at `key` by `decrement`. If the key does not exist, it is set to zero before performing the operation. An error is returned if the key contains a value of the wrong type, or contains a string that cannot be represented as an integer.

func (*Client) Del

func (c *Client) Del(keys ...string) *goja.Promise

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

func (*Client) Exists

func (c *Client) Exists(keys ...string) *goja.Promise

Exists returns the number of key arguments that exist. Note that if the same existing key is mentioned in the argument multiple times, it will be counted multiple times.

func (*Client) Expire

func (c *Client) Expire(key string, seconds int) *goja.Promise

Expire sets a timeout on key, after which the key will automatically be deleted. Note that calling Expire with a non-positive timeout will result in the key being deleted rather than expired.

func (*Client) Get

func (c *Client) Get(key string) *goja.Promise

Get returns the value for the given key.

If the key does not exist, the promise is rejected with an error.

If the key does not exist, the promise is rejected with an error.

func (*Client) GetDel

func (c *Client) GetDel(key string) *goja.Promise

GetDel gets the value of key and deletes the key.

If the key does not exist, the promise is rejected with an error.

func (*Client) GetSet

func (c *Client) GetSet(key string, value interface{}) *goja.Promise

GetSet sets the value of key to value and returns the old value stored

If the provided value is not a supported type, the promise is rejected with an error.

func (*Client) Hdel

func (c *Client) Hdel(key string, fields ...string) *goja.Promise

Hdel deletes the specified fields from the hash stored at `key`.

func (*Client) Hget

func (c *Client) Hget(key, field string) *goja.Promise

Hget returns the value associated with `field` in the hash stored at `key`.

If the hash does not exist, this command rejects the promise with an error.

func (*Client) Hgetall

func (c *Client) Hgetall(key string) *goja.Promise

Hgetall returns all fields and values of the hash stored at `key`.

If the hash does not exist, this command rejects the promise with an error.

func (*Client) Hincrby

func (c *Client) Hincrby(key, field string, increment int64) *goja.Promise

Hincrby increments the integer value of `field` in the hash stored at `key` by `increment`. If `key` does not exist, a new key holding a hash is created. If `field` does not exist the value is set to 0 before the operation is set to 0 before the operation is performed.

func (*Client) Hkeys

func (c *Client) Hkeys(key string) *goja.Promise

Hkeys returns all fields of the hash stored at `key`.

If the hash does not exist, this command rejects the promise with an error.

func (*Client) Hlen

func (c *Client) Hlen(key string) *goja.Promise

Hlen returns the number of fields in the hash stored at `key`.

If the hash does not exist, this command rejects the promise with an error.

func (*Client) Hset

func (c *Client) Hset(key string, field string, value interface{}) *goja.Promise

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

If the hash does not exist, this command rejects the promise with an error.

func (*Client) Hsetnx

func (c *Client) Hsetnx(key, field, value string) *goja.Promise

Hsetnx sets the specified field in the hash stored at `key` to `value`, only if `field` does not yet exist. If `key` does not exist, a new key holding a hash is created. If `field` already exists, this operation has no effect.

func (*Client) Hvals

func (c *Client) Hvals(key string) *goja.Promise

Hvals returns all values of the hash stored at `key`.

If the hash does not exist, this command rejects the promise with an error.

func (*Client) Incr

func (c *Client) Incr(key string) *goja.Promise

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

func (*Client) IncrBy

func (c *Client) IncrBy(key string, increment int64) *goja.Promise

IncrBy increments the number stored at `key` by `increment`. If the key does not exist, it is set to zero before performing the operation. An error is returned if the key contains a value of the wrong type, or contains a string that cannot be represented as an integer.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client is connected to redis.

func (*Client) Lindex

func (c *Client) Lindex(key string, index int64) *goja.Promise

Lindex returns the specified element of the list stored at `key`. The index is zero-based. Negative indices can be used to designate elements starting at the tail of the list.

If the list does not exist, this command rejects the promise with an error.

func (*Client) Llen

func (c *Client) Llen(key string) *goja.Promise

Llen 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.

If the list does not exist, this command rejects the promise with an error.

func (*Client) Lpop

func (c *Client) Lpop(key string) *goja.Promise

Lpop removes and returns the first element of the list stored at `key`.

If the list does not exist, this command rejects the promise with an error.

func (*Client) Lpush

func (c *Client) Lpush(key string, values ...interface{}) *goja.Promise

Lpush inserts all the specified values at the head of the list stored at `key`. If `key` does not exist, it is created as empty list before performing the push operations. When `key` holds a value that is not a list, and error is returned.

func (*Client) Lrange

func (c *Client) Lrange(key string, start, stop int64) *goja.Promise

Lrange returns the specified elements of the list stored at `key`. The offsets start and stop are zero-based indexes. These offsets can be negative numbers, where they indicate offsets starting at the end of the list.

func (*Client) Lrem

func (c *Client) Lrem(key string, count int64, value string) *goja.Promise

Lrem removes the first `count` occurrences of `value` from the list stored at `key`. If `count` is positive, elements are removed from the beginning of the list. If `count` is negative, elements are removed from the end of the list. If `count` is zero, all elements matching `value` are removed.

If the list does not exist, this command rejects the promise with an error.

func (*Client) Lset

func (c *Client) Lset(key string, index int64, element string) *goja.Promise

Lset sets the list element at `index` to `element`.

If the list does not exist, this command rejects the promise with an error.

func (*Client) Mget

func (c *Client) Mget(keys ...string) *goja.Promise

Mget returns the values associated with the specified keys.

func (*Client) Persist

func (c *Client) Persist(key string) *goja.Promise

Persist removes the existing timeout on key.

func (*Client) RandomKey

func (c *Client) RandomKey() *goja.Promise

RandomKey returns a random key.

If the database is empty, the promise is rejected with an error.

func (*Client) Rpop

func (c *Client) Rpop(key string) *goja.Promise

Rpop removes and returns the last element of the list stored at `key`.

If the list does not exist, this command rejects the promise with an error.

func (*Client) Rpush

func (c *Client) Rpush(key string, values ...interface{}) *goja.Promise

Rpush inserts all the specified values at the tail of the list stored at `key`. If `key` does not exist, it is created as empty list before performing the push operations.

func (*Client) Sadd

func (c *Client) Sadd(key string, members ...interface{}) *goja.Promise

Sadd adds 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.

func (*Client) SendCommand

func (c *Client) SendCommand(command string, args ...interface{}) *goja.Promise

SendCommand sends a command to the redis server.

func (*Client) Set

func (c *Client) Set(key string, value interface{}, expiration int) *goja.Promise

Set the given key with the given value.

If the provided value is not a supported type, the promise is rejected with an error.

The value for `expiration` is interpreted as seconds.

func (*Client) Sismember

func (c *Client) Sismember(key string, member interface{}) *goja.Promise

Sismember returns if member is a member of the set stored at key.

func (*Client) Smembers

func (c *Client) Smembers(key string) *goja.Promise

Smembers returns all members of the set stored at key.

func (*Client) Spop

func (c *Client) Spop(key string) *goja.Promise

Spop removes and returns a random element from the set value stored at key.

If the set does not exist, the promise is rejected with an error.

func (*Client) Srandmember

func (c *Client) Srandmember(key string) *goja.Promise

Srandmember returns a random element from the set value stored at key.

If the set does not exist, the promise is rejected with an error.

func (*Client) Srem

func (c *Client) Srem(key string, members ...interface{}) *goja.Promise

Srem removes the specified members from the set stored at key. Specified members that are not a member of this set are ignored. If key does not exist, it is treated as an empty set and this command returns 0.

func (*Client) Ttl

func (c *Client) Ttl(key string) *goja.Promise

Ttl returns the remaining time to live of a key that has a timeout.

type ModuleInstance

type ModuleInstance struct {
	*Client
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the JS module.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exports of the JS module.

func (*ModuleInstance) NewClient

func (mi *ModuleInstance) NewClient(call goja.ConstructorCall) *goja.Object

NewClient is the JS constructor for the redis Client.

Under the hood, the redis.UniversalClient will be used. The universal client supports failover/sentinel, cluster and single-node modes. Depending on the options, the internal universal client instance will be one of those.

The type of the underlying client depends on the following conditions: 1. If the MasterName option is specified, a sentinel-backed FailoverClient is used. 2. if the number of Addrs is two or more, a ClusterClient is used. 3. Otherwise, a single-node Client is used.

To support being instantiated in the init context, while not producing any IO, as it is the convention in k6, the produced Client is initially configured, but in a disconnected state. In order to connect to the configured target instance(s), the `.Connect` should be called.

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create Client instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface and returns a new instance for each VU.

Jump to

Keyboard shortcuts

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