Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand PHP operation redis

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

PHP operation redis how to understand, in view of this problem, this article introduces in detail the corresponding analysis and solutions, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Redis is an open source API that is written in ANSI C language, supports the network, can be memory-based and persistent, and provides API in multiple languages.

The data types supported by Redis are Stirng (string), List (list), Hash (dictionary), Set (collection), Sorted Set (ordered collection).

The redis version is Redis 2.6.12. The system is in Windows+Apache2.4+php5.6.

Connection:

Click (here) to collapse or open

/ / instantiate redis

$redis = new Redis ()

/ / Connect

$redis- > connect ('127.0.0.1 dollars, 6379)

/ / check whether the connection is successful

Echo "Server is running:". $redis- > ping ()

/ / output result Server is running: + PONG

Strng (string):

Click (here) to collapse or open

/ / set the value of a string

$redis- > set ('cat', 111)

/ / get the value of a string

Echo $redis- > get ('cat'); / / 111

/ / repeat set

$redis- > set ('cat', 222)

Echo $redis- > get ('cat');

List (list):

Click (here) to collapse or open

/ / list

/ / store data in the list

$redis- > lpush ('list',' html')

$redis- > lpush ('list',' css')

$redis- > lpush ('list',' php')

/ / get all the values in the list

$list = $redis- > lrange ('list', 0,-1)

Print_r ($list); echo'

'

/ / add one from the right

$redis- > rpush ('list',' mysql')

$list = $redis- > lrange ('list', 0,-1)

Print_r ($list); echo'

'

/ / one pops up from the left

$redis- > lpop ('list')

$list = $redis- > lrange ('list', 0,-1)

Print_r ($list); echo'

'

/ / one pops up from the right

$redis- > rpop ('list')

$list = $redis- > lrange ('list', 0,-1)

Print_r ($list); echo'

'

/ / result

/ / Array ([0] = > php [1] = > css [2] = > html)

/ / Array ([0] = > php [1] = > css [2] = > html [3] = > mysql)

/ / Array ([0] = > css [1] = > html [2] = > mysql)

/ / Array ([0] = > css [1] = > html)

Click (here) to collapse or open

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report