Redis – PHP

Before you start using Redis in your PHP programs, you need to make sure that you have Redis PHP driver and PHP set up on the machine.

Installation

Now, let us check how to set up Redis PHP driver.

You need to download the phpredis from github repository https://github.com/nicolasff/phpredis. Once you’ve downloaded it, extract the files to phpredis directory. On Ubuntu, install the following extension.

cd phpredis 
sudo phpize 
sudo ./configure 
sudo make 
sudo make install

Now, copy and paste the content of “modules” folder to the PHP extension directory and add the following lines in php.ini.

extension = redis.so

Now, your Redis PHP installation is complete

Connect to Redis Server

<?php 
   //Connecting to Redis server on localhost 
   $redis = new Redis(); 
   $redis->connect('127.0.0.1', 6379); 
   echo "Connection to server sucessfully"; 
   //check whether server is running or not 
   echo "Server is running: ".$redis->ping(); 
?>

When the program is executed, it will produce the following result.

Connection to server sucessfully 
Server is running: PONG 

Redis PHP String Example

<?php 
   //Connecting to Redis server on localhost 
   $redis = new Redis(); 
   $redis->connect('127.0.0.1', 6379); 
   echo "Connection to server sucessfully"; 
   //set the data in redis string 
   $redis->set("Adglob-name", "Redis Adglob"); 
   // Get the stored data and print it 
   echo "Stored string in redis:: " .$redis→get("Adglob-name"); 
?>

When the above program is executed, it will produce the following result.

Connection to server sucessfully 
Stored string in redis:: Redis Adglob 

Redis php List Example

<?php 
   //Connecting to Redis server on localhost 
   $redis = new Redis(); 
   $redis->connect('127.0.0.1', 6379); 
   echo "Connection to server sucessfully"; 
   //store data in redis list 
   $redis->lpush("Adglob-list", "Redis"); 
   $redis->lpush("Adglob-list", "Mongodb"); 
   $redis->lpush("Adglob-list", "Mysql");  
   
   // Get the stored data and print it 
   $arList = $redis->lrange("Adglob-list", 0 ,5); 
   echo "Stored string in redis:: "; 
   print_r($arList); 
?>

When the above program is executed, it will produce the following result.

Connection to server sucessfully 
Stored string in redis:: 
Redis 
Mongodb 
Mysql 

Redis PHP Keys Example

<?php 
   //Connecting to Redis server on localhost 
   $redis = new Redis(); 
   $redis->connect('127.0.0.1', 6379); 
   echo "Connection to server sucessfully"; 
   // Get the stored keys and print it 
   $arList = $redis->keys("*"); 
   echo "Stored keys in redis:: " 
   print_r($arList); 
?>

When the program is executed, it will produce the following result.

Connection to server sucessfully 
Stored string in redis:: 
Adglob-name 
Adglob-list 

This Post Has 137 Comments

  1. Julissa

    What’s up, just wanted to mention, I liked
    this blog post. It was funny. Keep on posting!

  2. K Z

    Thanks for your appreciation.

  3. SUPERSLOT

    I think this is a real great post.Really thank you! Much obliged.

  4. Tawjeeh Center

    Thanks so much for the article post.Thanks Again. Great.

  5. Training Center

    Im obliged for the blog.Really thank you! Awesome.

  6. male prostate massager

    I cannot thank you enough for the article post.Much thanks again. Really Great.

  7. ac repairing

    Im thankful for the blog post. Fantastic.

  8. askmebet

    Really enjoyed this blog article. Keep writing.

  9. mix parlay

    Very neat article.Really looking forward to read more. Fantastic.

  10. Rarest phenomenas

    I think this is a real great blog post.Much thanks again.

  11. dulhan set

    I value the blog post.Much thanks again. Cool.

  12. slinky web

    A round of applause for your post.Thanks Again.

  13. مسلسلات

    Thank you for your blog article.Much thanks again. Will read on…

  14. Exipure tablets reviews

    Looking forward to reading more. Great blog article.Really looking forward to read more. Will read on…

  15. vibrator

    I think this is a real great blog post.Thanks Again. Really Cool.

  16. Appreciate you sharing, great blog post.Really looking forward to read more. Really Cool.

  17. Furniture

    Thank you ever so for you article. Fantastic.

  18. slot

    Major thanks for the article.Really looking forward to read more. Want more.

  19. gun cleaning kit

    I really like and appreciate your article post.Thanks Again. Will read on…

  20. all in stroker

    Im grateful for the blog article.Much thanks again. Awesome.

  21. body wand massager

    Say, you got a nice blog post.Much thanks again. Really Cool.

  22. thrusting dildo

    Thanks for sharing, this is a fantastic article.Really thank you! Cool.

  23. rummy wealth

    Enjoyed every bit of your blog. Want more.

  24. ummy gold apk

    Very neat article post.Really thank you! Want more.

  25. 818king

    Great article.Really thank you!

  26. marcus dildo

    Looking forward to reading more. Great blog.Thanks Again. Great.

  27. ambbetx

    Thanks for sharing, this is a fantastic article post.Thanks Again. Fantastic.

  28. indian porn video

    I think this is a real great article.Thanks Again. Want more.

  29. pornovitube.com

    Thanks-a-mundo for the article.Really thank you! Cool.

  30. joymall

    Very neat article.Really thank you! Fantastic.

  31. life like dildo

    Thanks again for the post.Much thanks again. Cool.

  32. menstruation

    Great post.Thanks Again. Fantastic.

  33. this

    Im grateful for the article.Really looking forward to read more. Keep writing.

  34. thrusting rabbit

    Awesome article post.Much thanks again. Much obliged.

  35. look these up

    Im grateful for the blog.Thanks Again. Fantastic.

  36. Karimmlee Chaturbate

    A round of applause for your article.Really looking forward to read more. Will read on…

  37. muller

    Very good article.Thanks Again. Fantastic.

  38. eco styler gel

    Thank you ever so for you blog post.Thanks Again. Much obliged.

  39. mp3juice

    I really like and appreciate your article.Much thanks again.

  40. article source

    Enjoyed every bit of your article post.Really thank you! Want more.

  41. contractor

    Thanks so much for the article post.Thanks Again. Fantastic.

  42. driveway crack repair

    A round of applause for your blog article.Really thank you! Really Great.

  43. moneyline betting

    A round of applause for your blog.Really thank you! Will read on…

  44. best vibrator

    Thanks for sharing, this is a fantastic blog post. Much obliged.

  45. best vibrating dildo

    Really appreciate you sharing this blog article.Much thanks again. Awesome.

  46. see page

    Thanks so much for the article post. Much thanks again. Awesome.

  47. this website

    I really like and appreciate your blog article. Much thanks again.

  48. Merchant Referral

    Thanks again for the article post.Really thank you! Want more.

  49. resource

    Hey, thanks for the blog article. Really looking forward to read more. Will read on…

  50. slot joker

    wow, awesome blog article.Much thanks again. Want more.

  51. Suboxone For Sale

    Looking forward to reading more. Great blog article.Thanks Again. Will read on…

  52. check it out

    Muchos Gracias for your post. Really looking forward to read more. Keep writing.

  53. slot

    Thanks so much for the article post. Really Cool.

  54. porn

    Thanks so much for the article post.Much thanks again.

  55. slot online

    Thanks a lot for the article post.Much thanks again. Really Cool.

  56. สล็อต

    Thank you ever so for you article post.Really thank you! Cool.

  57. scarsdale movers

    I really like and appreciate your blog post.Much thanks again.

  58. Pretty! This has been an extremely wonderful article. Thanks for supplying this information.

  59. That is a good tip especially to those fresh to the blogosphere. Short but very accurate information… Many thanks for sharing this one. A must read post!

  60. Howdy! I could have sworn I’ve visited your blog before but after browsing through some of the posts I realized it’s new to me. Regardless, I’m certainly delighted I stumbled upon it and I’ll be bookmarking it and checking back regularly!

  61. click here

    Everyone loves it when individuals get together and share thoughts. Great website, continue the good work!

  62. official website

    Aw, this was a really good post. Spending some time and actual effort to make a good article… but what can I say… I put things off a whole lot and don’t manage to get anything done.

  63. You are so awesome! I don’t think I’ve truly read something like this before. So great to find somebody with a few genuine thoughts on this topic. Seriously.. thank you for starting this up. This site is one thing that is required on the internet, someone with a bit of originality.

  64. explanation

    This site definitely has all the info I wanted concerning this subject and didn’t know who to ask.

  65. mp3juices red

    I used to be able to find good advice from your blog posts.

  66. This site was… how do you say it? Relevant!! Finally I’ve found something that helped me. Cheers!

  67. mp3juices

    It’s difficult to find educated people on this subject, however, you sound like you know what you’re talking about! Thanks

  68. mp3juice downloads

    Aw, this was an incredibly nice post. Taking a few minutes and actual effort to create a superb article… but what can I say… I hesitate a whole lot and never seem to get anything done.

  69. klik disini

    Very good info. Lucky me I discovered your site by chance (stumbleupon). I’ve book marked it for later!

  70. mp3juice

    I love it whenever people get together and share views. Great website, stick with it.

  71. glimpse of us mp3

    I like reading a post that will make people think. Also, thanks for permitting me to comment.

  72. mp3juices

    You have made some really good points there. I checked on the net for additional information about the issue and found most people will go along with your views on this site.

  73. klik untuk baca

    I like reading through a post that will make people think. Also, many thanks for allowing me to comment.

  74. klik untuk lihat

    Aw, this was a really good post. Taking the time and actual effort to produce a really good article… but what can I say… I procrastinate a lot and don’t manage to get anything done.

  75. slot bola

    A round of applause for your post.Thanks Again. Really Cool.

  76. Get the facts

    Everything is very open with a very clear explanation of the challenges. It was really informative. Your site is useful. Many thanks for sharing!

  77. web

    Pretty! This was an incredibly wonderful article. Thanks for providing this information.

  78. linked here

    This site was… how do I say it? Relevant!! Finally I have found something that helped me. Appreciate it!

  79. brutal porn

    Very good information. Lucky me I discovered your site by chance (stumbleupon). I’ve saved it for later!

  80. tubidy

    Excellent blog you have got here.. It’s difficult to find excellent writing like yours these days. I truly appreciate people like you! Take care!!

  81. mature porn

    Howdy! I just would like to offer you a big thumbs up for the great info you have right here on this post. I’ll be returning to your web site for more soon.

  82. this page

    I like it when folks get together and share thoughts. Great blog, keep it up.

  83. abusive porn

    Great info. Lucky me I recently found your blog by accident (stumbleupon). I have book-marked it for later!

  84. milf porn

    There is certainly a great deal to find out about this issue. I really like all of the points you’ve made.

  85. mp3juices

    This is a topic that’s near to my heart… Thank you! Exactly where are your contact details though?

  86. tubidy mp3

    There’s certainly a lot to find out about this issue. I like all of the points you made.

  87. tubidy mp3

    There’s certainly a great deal to find out about this subject. I really like all of the points you have made.

  88. best site

    There’s definately a great deal to learn about this topic. I love all the points you’ve made.

  89. lesbian porn

    Howdy! I simply want to give you a big thumbs up for the great info you have here on this post. I’ll be coming back to your website for more soon.

  90. سمعها

    bookmarked!!, I really like your site.

  91. view publisher site

    Very good article. I definitely love this site. Keep writing!

  92. that site

    Great article! We are linking to this great post on our website. Keep up the good writing.

  93. سمعها

    I used to be able to find good info from your content.

Leave a Reply