The default port number of Redis is 6379
The default 16 databases, similar array subscripts start from 0, The initial default is to use library No. 0.
Use the command select <dbid></dbid>
to switch databases. Such as: select 8.
Unified password management, all libraries have the same password.
dbsize
View the number of keys in the current database. flushdb
Clear the current library. flushall
Kill all libraries.
Redis is a single-threaded multi-channel IO multiplexing technology.
Multiplexing refers to using one thread to check the readiness status of multiple file descriptors (Socket), such as calling the select and poll functions and passing in multiple file descriptors. If one file descriptor is ready, then Return, otherwise block until timeout. After getting the ready state, the actual operation can be performed in the same thread, or thread execution can be started (such as using a thread pool).
Serial VS Multi-thread lock (memcached) VS Single-threaded multi-channel IO multiplexing(Redis)
Redis and Memcache Three differences:
Support multiple data types
Support persistence
Single thread multiple Road IO multiplexing
keys *
: View all keys in the current library (matching: keys *1)
##exists key: Determine whether a key exists.
type key: Check what type your key is.
del key: Delete the specified key data,
unlink key: Select non-blocking deletion based on value. Only keys are deleted from keyspace metadata, and the actual deletion will be performed asynchronously later. .
expire key 10: 10 seconds, set the expiration time for the given key,
ttl key: Check how many seconds there are left to expire, -1 means never Expired, -2 means expired.
selectCommand to switch databases,
dbsizeView the number of keys in the current database.
flushdbClear the current library.
flushallkill all libraries
String type is binary safe. It means that Redis string can contain any data. For example, jpg pictures
or serialized objects.
String type is the most basic data type of Redis. A string value in Redis can be up to 512M.
set : Add key-value pairs.
When a key with a set value is set to a new value, the new value will overwrite the old one.
*NX: When the key does not exist in the database, the key-value can be added to the database.*XX: When the key exists in the database, key-value can be added to the database, which is mutually exclusive with NX parameters.
*EX: Key timeout seconds.
*PX: key’s timeout in milliseconds, mutually exclusive with EX.
get Query the corresponding key value.
append Append the given Append to the end of the original value,
strlen Get the length of the value.
setnx Set the value of the key only when the key does not exist.
incrIncrease the numerical value stored in key by 1.
Can only operate on numeric values. If it is empty, the new value is 10
decrDecrease the numeric value stored in key by 1 .
Can only operate on numeric values. If it is empty, the new value is -1.
inrjy/ decrby <step> Increase or decrease the numerical value stored in key. Custom step size. </step>
incr and decr are atomic operations
but i in java is not an atomic operation
msetSet one or more key-value pairs at the same time. ##mget....
Get one or more values at the same time.
msetnx
It is atomic
Set one or more key-value pairs at the same time ,succeeds if and only if all given keys do not exist.
If one of them exists before, it will not succeed
getrange, setrange
getrange
Get the range of values, similar to substring in java, front package, back package
setrange
Overwrites the stored string value with, starting from ##Replace the old value String data structure #The internal space capacity is usually larger than the actual string length len, as shown in the figure. If the string length is less than 1M, the existing space will be doubled when expanding. But if the length exceeds 1M, only 1M of space will be added each time it is expanded. It should be noted that the maximum length of the string is 512M. setex
While setting the key value, set the expiration time in seconds.
Replace the old value with the new one, The new value is set and the old value is obtained.
SDS is the abbreviation of String data structure, which represents the data structure of a simple dynamic string. It is a string that can be modified. The internal structure is similar to Java's ArrayList. It uses pre-allocated redundant space to reduce frequent allocation of memory.
The above is the detailed content of What are the common commands for keys and strings in Redis?. For more information, please follow other related articles on the PHP Chinese website!