RedisStoragePlug class
A storage implementation using Redis as the backend.
This class provides persistent storage using Redis, a fast in-memory data store. It supports:
- Thread-safe operations
- Data expiration
- Locking mechanisms
- Type-safe data storage and retrieval
Example usage:
final storage = RedisStoragePlug(
host: 'localhost',
port: 6379,
password: 'your_password',
);
await storage.init();
await storage.open<String>(expiry: Duration(hours: 1));
await storage.put('key', 'value');
final value = await storage.get<String>('key');
Constructors
- RedisStoragePlug({required String host, required int port, String? password})
- Creates a new RedisStoragePlug with the given configuration.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- host → String
-
The Redis server host.
final
- initialized ↔ bool
-
Whether the storage has been initialized.
getter/setter pair
- len → int
-
Gets the number of open caches.
no setter
- password → String?
-
The Redis server password, if any.
final
- port → int
-
The Redis server port.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close<
T extends Object> () → Future< PluggableStorageProvider> - Closes the cache for the specified type.
-
containsKey<
T extends Object> (String key) → Future< bool> - Checks if a key exists in the storage for the specified type.
-
dispose(
) → Future< PluggableStorageProvider> -
Disposes of the storage provider
inherited
-
dump<
T extends Object> () → Future< PluggableStorageProvider> - Clears all data of the specified type from the storage.
-
get<
T extends Object> (String key, [Fetch< T> ? fetch, String? trace]) → Future<T?> - Retrieves a value from storage by key.
-
getAllForType(
String type, [String? key]) → Future< Map< String, dynamic> > - Gets all stored values for a specific type, optionally filtered by key.
-
getAndPut<
T extends Object> (String key, T value, [String? trace]) → Future< T?> - Retrieves a value from storage and replaces it with a new value.
-
inFlightRequest<
T extends Object> (String key) → Future< T?> -
Gets the result of an in-flight request
inherited
-
init(
) → Future< PluggableStorageProvider> - Initializes the storage provider.
-
isKeyInFlight<
T extends Object> (String key) → bool -
Checks if a request is in-flight
inherited
-
isPrimitiveType<
T extends Object> () → bool -
Checks if a type is a primitive type
inherited
-
keys<
T extends Object> () → Future< Iterable< String> > - Returns all keys stored for the specified type.
-
markAsInFlight<
T extends Object> (String key) → void -
Marks a request as in-flight
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open<
T extends Object> ({required Duration expiry, DecodeFunc< T> ? fromEncodable}) → Future<void> - Opens a cache for the specified type with the given configuration.
-
ping(
) → Future< Map< String, dynamic> > - Pings all open Redis connections to check their health.
-
put<
T extends Object> (String key, T? value, [String? trace]) → Future< void> - Stores a value in the storage with the specified key.
-
putIfAbsent<
T extends Object> (String key, T value, [String? trace]) → Future< bool> - Stores a value in the storage only if the key doesn't already exist.
-
removeInFlight<
T extends Object> (String key) → void -
Removes an in-flight request
inherited
-
resolveInFlightRequest<
T extends Object> (String key, T? value) → void -
Resolves an in-flight request with a value
inherited
-
sameType<
X extends Plug< (X> >) → bool -
Checks if this plug is of the same type as another plug.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited