This PHP tutorial helps to work the Redis module with php, We will install Redis server into windows and PHP extension of redis into xampp. This tutorial also has a simple PHP script to communicate with redis and php.
I am using redis in PHP application to create a Cache system for faster access to data. This means that Redis is fast, but is also non-volatile.I am using php_redis client but you can use other redis clients as well like Predis.
Redis as an advanced key-value database storage system, Redis can also support complex data structures like strings, hashes, lists, sets, sorted sets, bitmaps and hyperlogs as its key values. It’s often referred to as a NoSQL database.
Redis is an open source(BSD licensed), in-memory data structure store, used as a database, cache and message broker written in C. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with redis queries.
Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
We will download redis for window from Here. You can download redis separately for windows32 and windows 64. You can get redis command information from Redis Commands Docs.
Also checkout other tutorials of PHP Cache,
We will follow the following steps to install redis server into windows.
d:\redis
directory.redis-server.exe
from d:\redis
directory.redis-cli.exe
from d:\redis
directory.We can enable redis PHP extension by following steps:
php_redis.dll
file from PECL libs. Download the extension as per your current PHP version.D:\XAMPP\php\ext
).php.ini
file and add extension=php_redis.dll
line to this file.We will create a simple PHP script that will set the key into redis and get the key value from Redis server. The Redis() method helps to create instance of redis. The $redis->set(key, val) method is used to store value against the key name. The $redis->get(keyname) method is used to get the stored value of the passed key name.
try { //create redis instance $redis = new Redis(); //connect with server and port $redis->connect('localhost', 6379); //set value $redis->set('website', 'www.phpflow.com'); //get value $website = $redis->get('website'); //print www.phpflow.com echo $website; } catch (Exception $ex) { echo $ex->getMessage(); }
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More