Download the windows version of redis: https://github.com/MSOpenTech/redis/releases
I downloaded 3.2
Installation: Then extract it to a custom folder. I created a redis directory on the C drive according to the rookie tutorial , and then extracted the downloaded file to the newly created redis directory .
Startup: Start the server first , open the command window in the C drive redis directory and enter the command:
redis-server.exe redis.windows.conf
The following interface appears, indicating that the redis service gas end is successfully installed
Re-open a command window and enter the command
redis-cli.exe -h 127.0.0.1 -p 6379
Used to start the client, the following interface appears to indicate that the connection is successful
There are 5 Redis data types
1. string ( string type )
2. Hash _
Just the keys don't get it, just the test
3. List _
4. Set ( collection )
one. An error occurred when adding (error) WRONGTYPE Operation against a key holding the wrong kind of value
Because the key name is repeated, change its key name or delete the previous runnob
2. Although redis is added twice, the elements inserted for the second time will be ignored according to the uniqueness of the elements in the collection
5. Zset ( ordered set )
There is also a special Hyperloglog ( for counting the number of elements, does not save the value of the element )
Note that 'single quotes are also ok
delete key
Del key name
publish subscribe
SUBSCRIBE redisChat creates a subscription channel named redisChat :
Restart a redis client and publish two messages on the same channel redisChat, and subscribers can receive the message
PUBLISH redisChat "Redis is a great caching technique"
client
affairs
get cannot be lowercase
script
Redis scripts use the Lua interpreter to execute scripts
EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second
Redis data backup and recovery
The Redis SAVE command is used to create a backup of the current database.
If you need to restore the data, just move the backup file (dump.rdb) to the redis installation directory and start the service. To get the redis directory, you can use the CONFIG command
Creating a redis backup file can also be done with the command BGSAVE , which is executed in the background.
Safety
CONFIG get requirepass
Check if password authentication is set
The requirepass parameter is empty by default , which means you can connect to the redis service without password authentication.
CONFIG set requirepass "123456"
Use the above command to set the password,
After the password is set, the client needs password authentication to connect to the redis service , otherwise the command cannot be executed.
127.0.0.1:6379> AUTH password
Phpredis download: http://pecl.php.net/package/redis/3.1.6/windows
Edit the php.ini extension of apache and add it yourself
Restart apache , check phpinfo() and the following interface appears to indicate success
test:
Create a new test.php in the root directory
<?php
// Connect to the local Redis service
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth('123456'); // You can use this sentence without a password. Another way is to delete the password and enter the redis installation directory to modify the redis configuration file, that is , delete the requirepass " 123456 " in redis.windows.conf just fine
echo "Connection to server sucessfully";
// Set redis string data
$redis->set("tutorial-name", "Redis tutorial");
// get the stored data and output
echo "Stored string in redis:: " . $redis->get("tutorial-name");
?>
In the browser, the following interface appears to indicate success
Set the redis server to start automatically at boot
redis-server.exe --service-install redis.windows.conf
Then you can see the following interface in the service
At this point the service is off, start it manually. Wait until the next boot to start automatically
It is good to recommend a blog: https://www.cnblogs.com/aipiaoborensheng/p/5666005.html
/**************************************************** ****************CODE TEST********************************** ********************************/
<?php
header('Content-type:text/html;charset=utf-8');
$redis = new redis();
$redis->connect('127.0.0.1',6379);
$redis->auth ('123456');
//String type
//$redis->set('test','1111111');//Set the value of key and value
/*
$result = $redis->get('test' );//Get the value of key
var_dump($result);
$redis->delete('test');
var_dump($redis->get('test'));
*/
/*
$redis->setnx(' test',"22222");//The so-called SETNX, is the abbreviation of "SET if Not eXists", that is, set
echo only when it does not exist $redis->get('test');
*/
//var_dump( $redis->exists('test'));//Determine whether the key exists
//$redis->set('test',123);
//$redis->incr('test'); //Increment the key value of the key
//$redis->decr('test');//Decrement the key value of the key
//$redis->set('test1',11111);
//$redis->set('test2',22222);
//$result = $redis->getMultiple(['test1','test2'] );//Get the value of all specified keys
//echo $redis->get('test');
//var_dump($result);
//$redis->delete('test');
//var_dump($ redis->lpush('test','1111'));//Add string value to the head of the list
//var_dump($redis->rpush('test','2222'));//Add from the end of the list String value
$redis->delete('test');
//$redis->lpush("test","111");
//$redis->lpush("test","1111");
// $redis->lpush("test","11111");
//$redis->lpush("test","111111");
//var_dump($redis->lpop("test")); //return and remove the first element of the list
//var_dump($redis->lsize("test"));//length of the returned list
//var_dump($redis- >lget('test',1));//Returns the specified key stored in the specified element in the list.
112'); $redis->sadd('test','113'); var_dump($redis->scontains('test', '111'));//Check if the specified value exists in the collection. */
/*
$redis->sadd('test','111');
$redis->sadd('test','112');
echo $redis->ssize('test'); //return to store in the collection number of values
*/
/*
$redis->sadd("test","111");
$redis->sadd("test","222");
$redis->sadd("test","333" );
var_dump($redis->spop("test")); //Randomly remove and return a value in key
*/
$redis->sadd("test","111");
$redis->sadd ("test","222");
print_r($redis->smembers('test')); //Return everything in the collection
?>