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 realize the String Operation of Redis by php

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how php implements the String operation of Redis. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

String operation

/ / set key value: return true successfully, otherwise return false$redis- > set ('mystr',' Welcomeholders'); / / get key value: return key value of String type successfully, return false$ret = $redis- > get ('mystr') if key does not exist or is not String type; / / replace it with another specified string starting from the specified offset of the string stored in a key, and successfully return the length of the new string after replacement. $ret = $redis- > setRange ('mystr', 7,' to key'); / / gets the substring of the string stored in the specified string. $ret = $redis- > getRange ('mystr', 0,6); / / set the new value and return the old value: if the key does not exist, return false$ret = $redis- > getSet (' mystr','hi man'); / / set multiple key-value pairs at a time: true is returned successfully. $ret = $redis- > mset (['name' = >' jet', 'age' = > 18]); / / get the values of more than one key at a time: return an array of key-value pairs, where the non-existent key value is false. $ret = $redis- > mget (['name',' age']); / / sets the value of the specified key and its expiration time in seconds. / / parameters: key name, expiration time, key value. True was returned successfully. $ret = $redis- > setex ('name', 10,' jetwu'); / / sets the value and expiration time of the specified key in milliseconds. True was returned successfully. The value of $ret = $redis- > psetex ('name', 10,' jetwu'); / / the value of key does not exist. Key does not exist and a successful setting returns true, otherwise it returns false. $ret = $redis- > setnx ('name',' boby'); / / batch operation of the setnx command. It can be set successfully only if none of the given key exists, and none of the key can be set successfully as long as one of the key exists. $ret = $redis- > msetnx (['country' = >' China', 'city' = >' Shenzhen']); / / gets the length of the string stored in the specified key. If there is no key, 0 is returned and no false is returned for the string. $ret = $redis- > strlen ('name'); / / increments the numeric value stored by the specified key by 1. If key does not exist, it will be initialized to 0 and then incremented by 1. If the value stored by key is not an integer, false will be returned. The new value of key was returned successfully. $ret = $redis- > incr ('age'); / / adds the specified increment value to the numeric value stored by the specified key. $ret = $redis- > incrBy ('age', 10); / / adds the specified floating point increment to the numeric value stored by the specified key. $ret = $redis- > incrByFloat ('age', 1.5); / / subtracts the numeric value stored by the specified key by one. $ret = $redis- > decr ('age'); / / subtracts the specified decrement value from the numeric value stored by the specified key. $ret = $redis- > decrBy ('age', 10); / / appends the specified key value to the end of the original value, relative to the set () function if key does not exist. $ret = $redis- > append ('mystr',' '); thank you for reading! This is the end of this article on "how php implements the String operation of Redis". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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