append name 2222
strlen name
Article views, likes can be used This realization.
incr agedecr age
Note that this must be a number to proceed, so a key is reset.
The String type can store not only strings but also numbers.
If you want to bring the step size:
incrby age 5decrby age 8##4. String range
getrange name 1 3
getrange name 0 -1View all, similar to the string interception operation in python. 5. Replace the stringStart replacing the string at the specified position
setrange name 0 test6. Set the value and its expiration timesetex
setex mykey 60 redis
setnx mykey redis333#key exists, and the setting fails. 7. Batch operations1. mset, mgetmset, set multiple at one time.
mset k1 v1 k2 v2 k3 v3mget, get multiple at one time.
mget k1 k2 k32. msetnxNote that when setting multiple values here, as long as one of them fails, none of them will succeed.
msetnx k1 v1 k4 v48. Set a json objectIn actual applications, you may often need to save an object, so you can use colon: in redis Make some clever designs. For example, if you want it now
{name: pingguo, age:22}set it to a
user1, you can do this:
mset user:1:name pingguo user:1:age 22mget user:1:name user:1:agemset user:1:name pingguo user:1:age 22 mget user:1:name user:1:age
9. Getset first gets and then sets Just like the literal meaning, the value will be obtained first and then set.
If the value does not exist, return
nil. If it exists, get the original value and set the new value.
getset db mongodb
The above is the detailed content of What are the common operation commands for Redis's basic data type String?. For more information, please follow other related articles on the PHP Chinese website!