Documentation ¶
Overview ¶
Package redis implements a redis client for k6.
Index ¶
- type Client
- func (c *Client) Decr(key string) *goja.Promise
- func (c *Client) DecrBy(key string, decrement int64) *goja.Promise
- func (c *Client) Del(keys ...string) *goja.Promise
- func (c *Client) Exists(keys ...string) *goja.Promise
- func (c *Client) Expire(key string, seconds int) *goja.Promise
- func (c *Client) Get(key string) *goja.Promise
- func (c *Client) GetDel(key string) *goja.Promise
- func (c *Client) GetSet(key string, value interface{}) *goja.Promise
- func (c *Client) Hdel(key string, fields ...string) *goja.Promise
- func (c *Client) Hget(key, field string) *goja.Promise
- func (c *Client) Hgetall(key string) *goja.Promise
- func (c *Client) Hincrby(key, field string, increment int64) *goja.Promise
- func (c *Client) Hkeys(key string) *goja.Promise
- func (c *Client) Hlen(key string) *goja.Promise
- func (c *Client) Hset(key string, field string, value interface{}) *goja.Promise
- func (c *Client) Hsetnx(key, field, value string) *goja.Promise
- func (c *Client) Hvals(key string) *goja.Promise
- func (c *Client) Incr(key string) *goja.Promise
- func (c *Client) IncrBy(key string, increment int64) *goja.Promise
- func (c *Client) IsConnected() bool
- func (c *Client) Lindex(key string, index int64) *goja.Promise
- func (c *Client) Llen(key string) *goja.Promise
- func (c *Client) Lpop(key string) *goja.Promise
- func (c *Client) Lpush(key string, values ...interface{}) *goja.Promise
- func (c *Client) Lrange(key string, start, stop int64) *goja.Promise
- func (c *Client) Lrem(key string, count int64, value string) *goja.Promise
- func (c *Client) Lset(key string, index int64, element string) *goja.Promise
- func (c *Client) Mget(keys ...string) *goja.Promise
- func (c *Client) Persist(key string) *goja.Promise
- func (c *Client) RandomKey() *goja.Promise
- func (c *Client) Rpop(key string) *goja.Promise
- func (c *Client) Rpush(key string, values ...interface{}) *goja.Promise
- func (c *Client) Sadd(key string, members ...interface{}) *goja.Promise
- func (c *Client) SendCommand(command string, args ...interface{}) *goja.Promise
- func (c *Client) Set(key string, value interface{}, expiration int) *goja.Promise
- func (c *Client) Sismember(key string, member interface{}) *goja.Promise
- func (c *Client) Smembers(key string) *goja.Promise
- func (c *Client) Spop(key string) *goja.Promise
- func (c *Client) Srandmember(key string) *goja.Promise
- func (c *Client) Srem(key string, members ...interface{}) *goja.Promise
- func (c *Client) Ttl(key string) *goja.Promise
- type ModuleInstance
- type RootModule
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 ¶
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 ¶
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) Exists ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Hget ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
IsConnected returns true if the client is connected to redis.
func (*Client) Lindex ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) RandomKey ¶
RandomKey returns a random key.
If the database is empty, the promise is rejected with an error.
func (*Client) Rpop ¶
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 ¶
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 ¶
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 ¶
SendCommand sends a command to the redis server.
func (*Client) Set ¶
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) Spop ¶
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 ¶
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.
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 (*RootModule) NewModuleInstance ¶
func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance
NewModuleInstance implements the modules.Module interface and returns a new instance for each VU.