Extensions for Redis and Phpredis installed under Windows (Windows Redis PHP&PHP7)

Source: Internet
Author: User
Tags pconnect vars windows download redis server



First, tool preparation



1. Redis for Windows download Https://github.com/MSOpenTech/redis



2. php Extensions download http://pecl.php.net/package-stats.php (Redis and Igbinary)



PHP 7 extension Download http://windows.php.net/downloads/pecl/snaps/redis/20160319/



Note: Download extension is to watch your own PHP version and x86orx64 and compiler compiled version









Second, Redis installation



1.redis Installation



Unzip the downloaded Redis file to the installation directory






2.redis Boot






1). Windows+r then cmd into the D:\program Files\redis (self-tuning according to your Redis path)



2). Enter Redis-server.exe Click Enter to take a look at the Redis directory file situation, different versions of the startup mode a little difference. The identity execution occurred successfully. do not close the current window after success, to ensure that this window is open during Redis operation, close this window to close Reids, reopen a cmd







3). cmd go to D:\program files\redis (self-adjusting according to your Redis path) and enter Redis-cli.exe to click Return. Now we can do some tests. For example, the identity Redis installation started successfully.



Note: Two cmd windows open at the same time, the Redis window can not be turned off









Third, PHP extension



1. Copy the downloaded php_redis.dll and php_igbinary.dll extension files to the Php\ext



2. Open php.ini; Add the following code





[HTML]View PlainCopy
    1. #php for Redis
    2. extension=Php_igbinary.dll
    3. extension=Php_redis.dll





3. Restart the service, there are redis entries in Phpinfo to indicate success






Four. Demo





[PHP]View PlainCopy
  1. <span style="FONT-SIZE:18PX;"    >$redis = new Redis ();
  2. $redis->connect ("127.0.0.1","6379"); //php Client-set IP and port
  3. Store a value
  4. $redis->set ("type", 12);
  5. echo $redis->get ("type");
  6. Store multiple values
  7. $array = Array (' first_key ' = 'first_val ',
  8. ' second_key ' = 'second_val ',
  9. ' third_key ' = 'third_val ');
  10. $array _get = Array (' First_key ',' Second_key ',' Third_key ');
  11. $redis->mset ($array);
  12. Var_dump ($redis->mget ($array _get)); </span>








Attached: Some properties and methods of the Redis class




A) connect to Redis server


    • Connect: Connecting to server
    • Pconnect: Long Connection
    • AUTH: Permission Validation
    • Select: Choose DB
    • Close: Closing the connection
    • SetOption: Set client options
    • GetOption: Get Client options
    • ping:ping Redis Server
    • Echo: Output string


Note that if you operate redis frequently, and the connect and close will be very expensive, it is recommended to use Pconnect to establish a long connection.



b) string read and write function


    • Append: Append a value after a value
    • DECR: decrements the value of a key
    • INCR: Increments the value of a key
    • Get: Get a value
    • Set: Sets a value
    • Getset: Sets the value and returns the old value
    • MGet: Bulk Fetch values
    • MSet: Batch Setting values
    • Strlen: Get value length


Note: If you can use bulk operations as much as possible, reduce the frequent connection to Redis database performance



c) hash read and write function


    • Hdel: Delete a multiple domain
    • Hexists: Determine if a hash field exists
    • Hget: Gets the value of the hash field
    • Hgetall: Get all domain values
    • Hincrby: Self-growing value of a hash int field
    • Hkeys: Get hash all fields
    • Hlen: Get the number of domains
    • Hmget: Bulk Get the value of a domain
    • Hmset: Bulk set values for a field
    • Hset: Setting the value of a field
    • Hvals: Get values for all domains


d) List read and write function


    • Linsert: inserting elements
    • Llen:list length
    • Lpop: Remove and get the first color
    • Lpush: Inserting an element
    • Lrem: removing elements
    • LSet: Setting element values


E) Set


      • Sadd: Add one or more members
      • Sismember: Whether it contains
      • Smembers: Get member
      • Smove: Moving Members
      • SPop: removing members
      • Srandmember: Get randomly into


Extensions for Redis and Phpredis installed under Windows (Windows Redis PHP&PHP7)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.