diff --git a/services/nginx/app/classes/redis.php b/services/nginx/app/classes/redis.php index fbf908c7..fceadad2 100644 --- a/services/nginx/app/classes/redis.php +++ b/services/nginx/app/classes/redis.php @@ -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 diff --git a/services/nginx/app/interfaces/redis_i.php b/services/nginx/app/interfaces/redis_i.php index 2a7a919e..e97d2c39 100644 --- a/services/nginx/app/interfaces/redis_i.php +++ b/services/nginx/app/interfaces/redis_i.php @@ -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; } \ No newline at end of file