Struct fred::sync::borrowed::RedisClientRemote [] [src]

pub struct RedisClientRemote { /* fields omitted */ }

A Send and Sync wrapper around a redis client that borrows self on each command, instead of taking ownership over self. This pattern gives the caller more freedom to manage ownership over the value, such as when the client is wrapped with another struct.

However, this pattern is more tedious to use when commands are chained together in a single chain of futures as it requires the caller to either explicitly clone or move the client into those callbacks. For that reason it is not the default interface. However, if you intend on wrapping the client in another struct, or an Arc, or something that manages ownership and mutability for the inner value, then this interface is probably what you want. You will still have to manually move or clone the wrapper struct into callbacks as needed, but with this interface the ownership requirements are removed on all commands.

For example, one use case for this interface would be as follows:

  1. Create several RedisClient instances on an event loop.
  2. Create RedisClientRemote wrappers for them.
  3. Move each of the RedisClientRemote instances into another wrapper struct Foo.
  4. Wrap Foo in an Arc, and send clones of the Arc<Foo> to different threads.

If the commands on the RedisClientRemote instances required taking ownership over self then this pattern would be much more difficult to implement, since an Arc only allows for using functions that borrow the inner value. This interface is primarily designed to support this kind of usage.

See examples/sync_borrowed.rs for usage examples.

Methods

impl RedisClientRemote
[src]

[src]

Create a new, empty RedisClientRemote.

[src]

Convert a clone of this borrowed::RedisClientRemote to an owned::RedisClientRemote.

[src]

Convert this borrowed::RedisClientRemote to an owned::RedisClientRemote.

[src]

Read the state of the underlying connection.

[src]

Read latency metrics across all commands.

[src]

Read and consume latency metrics, resetting their values afterwards.

[src]

Read payload size metrics across all commands.

[src]

Read and consume payload size metrics, resetting their values afterwards.

[src]

Initialize the remote interface with an existing RedisClient. This must be called on the same thread that initialized the RedisClient.

The future returned by this function runs the message passing logic between this remote instance and the RedisClient argument on the event loop thread.

[src]

Flush and close the Sender channel this instance receives messages through.

[src]

Returns a future that resolves when the underlying client connects to the server. This function can act as a convenient way of notifying a separate thread when the client has connected to the server and can begin processing commands.

This can be called before init if needed, however the callback will not be registered on the underlying client until init is called. For this reason it's best to call init with a client that has not yet starting running its connection future.

See the examples/sync_borrowed.rs file for usage examples.

[src]

Listen for protocol and connection errors. This stream can be used to more intelligently handle errors that may not appear in the request-response cycle, and so cannot be handled by response futures.

Similar to on_message, this function does not need to be called again if the connection goes down.

[src]

Listen for (channel, message) tuples on the PubSub interface.

If the connection to the Redis server goes down for any reason this function does not need to be called again. Messages will start appearing on the original stream after subscribe is called again.

[src]

Select the database this client should use.

https://redis.io/commands/select

[src]

Subscribe to a channel on the PubSub interface. Any messages received before on_message is called will be discarded, so it's usually best to call on_message before calling subscribe for the first time. The usize returned here is the number of channels to which the client is currently subscribed.

https://redis.io/commands/subscribe

[src]

Unsubscribe from a channel on the PubSub interface.

https://redis.io/commands/unsubscribe

[src]

Publish a message on the PubSub interface, returning the number of clients that received the message.

https://redis.io/commands/publish

[src]

Read a value from Redis at key.

https://redis.io/commands/get

[src]

Set a value at key with optional NX|XX and EX|PX arguments. The bool returned by this function describes whether or not the key was set due to any NX|XX options.

https://redis.io/commands/set

[src]

Removes the specified keys. A key is ignored if it does not exist. Returns the number of keys removed.

https://redis.io/commands/del

[src]

Decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. Returns error if the key contains a value of the wrong type.

https://redis.io/commands/decr

[src]

Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. Returns error if the value at key is of wrong type.

https://redis.io/commands/incr

[src]

Increments the number stored at key by incr. If the key does not exist, it is set to 0 before performing the operation. Returns an error if the value at key is of the wrong type.

https://redis.io/commands/incrby

[src]

Increment the string representing a floating point number stored at key by the argument value. If the key does not exist, it is set to 0 before performing the operation. Returns error if key value is wrong type or if the current value or increment value are not parseable as float value.

https://redis.io/commands/incrbyfloat

[src]

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

https://redis.io/commands/hget

[src]

Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value Returns an empty hashmap if hash is empty.

https://redis.io/commands/hgetall

[src]

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. Note: Return value of 1 means new field was created and set. Return of 0 means field already exists and was overwritten.

https://redis.io/commands/hset

[src]

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.

https://redis.io/commands/hdel

[src]

Returns the number of fields contained in the hash stored at key.

https://redis.io/commands/hlen

[src]

Returns the values associated with the specified fields in the hash stored at key. Values in a returned list may be null.

https://redis.io/commands/hmget

[src]

Sets the specified fields to their respective values in the hash stored at key. This command overwrites any specified fields already existing in the hash. If key does not exist, a new key holding a hash is created.

https://redis.io/commands/hmset

[src]

Sets 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. Note: Return value of 1 means new field was created and set. Return of 0 means no operation performed.

https://redis.io/commands/hsetnx

[src]

Returns the string length of the value associated with field in the hash stored at key. If the key or the field do not exist, 0 is returned.

https://redis.io/commands/hstrlen

[src]

Returns all values in the hash stored at key. Returns an empty vector if the list is empty.

https://redis.io/commands/hvals

[src]

Returns all field names in the hash stored at key. Returns an empty vec if the list is empty. Null fields are converted to "nil".

https://redis.io/commands/hkeys

Trait Implementations

impl Clone for RedisClientRemote
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for RedisClientRemote
[src]

[src]

Formats the value using the given formatter.