To make use of Redis for session administration in Magento 2, you’ll must configure Magento to make the most of Redis because the session storage backend. Right here’s a step-by-step information on the way to set it up
Set up Redis
Be sure you have Redis put in and working in your server or native setting. You’ll be able to obtain Redis from the official web site and observe the set up directions in your working system.
Configure Magento 2 to make use of Redis for session storage:
1. Log in to your Magento 2 server or entry the Magento 2 codebase.
2. Within the Magento 2 root listing, open the `app/and so forth/env.php` file.
3. Find the `session` configuration part, which ought to appear like this:
'session' => [ 'save' => 'files', 'save_path' => 'path/to/session/files', ]
4. Substitute the ‘save‘ worth with ‘redis‘ and add a ‘redis‘ key to the ‘session‘ array with the Redis server configuration:
'session' => [ 'save' => 'redis', 'redis' => [ 'host' => '127.0.0.1', 'database' => '2', 'log_level' => '4', 'port' => '6379', 'password' => '', 'timeout' => '2.5', 'persistent_identifier' => '', 'compression_threshold' => '2048', 'compression_library' => 'gzip', 'max_concurrency' => '6', 'break_after_frontend' => '5', 'break_after_adminhtml' => '30', 'first_lifetime' => '600', 'bot_first_lifetime' => '60', 'bot_lifetime' => '7200', 'disable_locking' => '0', 'min_lifetime' => '60', 'max_lifetime' => '2592000', 'sentinel_master' => '', 'sentinel_servers' => '', 'sentinel_connect_retries' => '5', 'sentinel_verify_master' => '0' ] ]
5. Save the modifications to the `env.php` file.
Clear Magento cache: Clear the Magento cache to make sure the brand new session configuration takes impact. You are able to do this by working the next command from the Magento root listing:
php bin/magento cache: clear
Magento Firm ? Learn Extra
Check session administration with Postman:
1. Open Postman or any REST API testing device.
2. Set the HTTP methodology to POST.
3. Set the URL to your Magento 2 base URL adopted by
/relaxation/V1/integration/admin/token (e.g., `http://yourmagento2domain.com/relaxation/V1/integration/admin/token
).`form-data` and add the next key-value pairs:
4. Within the request physique, choose
`username`: Your Magento 2 admin username
`password`: Your Magento 2 admin password
5. Click on the “Ship” button to ship the request. This can return an entry token.
6. Copy the entry token from the response.
1. Set the HTTP methodology to GET.
2. Set the URL to your Magento 2 base URL adopted by /relaxation/V1/retailer/storeViews.
3. Add a header with the next key-value pair:
: Bearer [access_token]`[access_token]` with the entry token you obtained within the earlier step.
d. Click on the “Ship” button to ship the request. This can retrieve the shop views info.
Redis monitor command (Should you use Redis for session storage, you’ll see output much like the next)
Redis ping command
PONG must be the response.
redis-cli command reference
That’s it! You may have now configured Redis for session administration in Magento 2 and examined it utilizing Postman. You’ll be able to proceed exploring different Magento 2 REST APIs utilizing the entry token and applicable endpoints.
Leave a Reply