Add Redis caching methods for customer-user mappings
- Introduced methods `cache_customer_number_from_user_id`, `get_customer_number_from_user_id`, and `clear_customer_number_from_user_id` to the `Redis` class. - Updated the `Redis_i` interface to define these new methods. - Enhances customer-user mapping logic by integrating Redis for efficient caching and retrieval.
This commit is contained in:
@@ -380,6 +380,35 @@ class redis implements redis_i
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function cache_customer_number_from_user_id(int $user_id, int $customer_number): self
|
||||
{
|
||||
// Cache the customer number from user id
|
||||
$this->set('customer_number_from_user_id_' . $user_id, $customer_number);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get_customer_number_from_user_id(int $user_id): int|null
|
||||
{
|
||||
// Get the customer number from user id
|
||||
return $this->get('customer_number_from_user_id_' . $user_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function clear_customer_number_from_user_id(int $user_id): self
|
||||
{
|
||||
// Clear the customer number from user id
|
||||
$this->delete('customer_number_from_user_id_' . $user_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function expire(string $key, int $seconds): self
|
||||
{
|
||||
// Set the expiration time for a key
|
||||
|
||||
@@ -244,4 +244,26 @@ interface redis_i
|
||||
* @return self
|
||||
*/
|
||||
public function clear_user_id_from_customer_number(int $customer_number): self;
|
||||
|
||||
/**
|
||||
* Get a customer number from user id from the cache
|
||||
* @param int $user_id
|
||||
* @return int|null
|
||||
*/
|
||||
public function get_customer_number_from_user_id(int $user_id): int|null;
|
||||
|
||||
/**
|
||||
* Cache a customer number from user id
|
||||
* @param int $user_id
|
||||
* @param int $customer_number
|
||||
* @return self
|
||||
*/
|
||||
public function cache_customer_number_from_user_id(int $user_id, int $customer_number): self;
|
||||
|
||||
/**
|
||||
* Clear a customer number from user id from the cache
|
||||
* @param int $user_id
|
||||
* @return self
|
||||
*/
|
||||
public function clear_customer_number_from_user_id(int $user_id): self;
|
||||
}
|
||||
Reference in New Issue
Block a user