Redis provides the ping command to test whether the connection between the client and redis is normal. If pong is returned, the connection is normal. 127.0.0.1: 6389pingPONGecho print command 127.0.0.1: 6389 echohiboy! Hiboy! Through configget and configset, You can dynamically obtain and set redis configuration parameters, but not all parameters can be dynamically set, such as the PORT parameter.
Redis provides the ping command to test whether the connection between the client and redis is normal. If pong is returned, the connection is normal. 127.0.0.1: 6389 pingPONG echo print command 127.0.0.1: 6389 echo hi boy! Hi boy! Through config get and config set, you can dynamically obtain and set redis configuration parameters, but not all parameters can be dynamically set, such as the PORT parameter.
Redis provides the ping command to test whether the connection between the client and redis is normal. If pong is returned, the connection is normal. 127.0.0.1: 6389> pingPONG
Echo print command 127.0.0.1: 6389> echo "hi boy! "" Hi boy! "
Through config get and config set, you can dynamically obtain and set redis configuration parameters, but not all parameters can be dynamically set, such as the PORT parameter. To modify the port, you must restart the database. 127.0.0.1: 6389> config get port1) "port" 2) "6389" 127.0.0.1: 6389> config set loglevel warningOK select command select database of redis, which is equivalent to mysql database, it is also like the schema of oracle. By default, apsaradb for redis has 16 databases starting from 0 and does not support user-defined database names. 127.0.0.1: 6389> config get databases1) "databases" 2) "16" you can modify the database quantity by modifying the databases parameter.
Keys returns the matched key List redis 127.0.0.1: 6379> keys fwy * 1) "fwy2" 2) "fwy" KEYS command returns all matched keys of the current database, all keys are retrieved. Therefore, performance is affected when many keys exist. It is not recommended to use them in the production environment .? Match a character * match any character \ x escape, for example \? Matching? 127.0.0.1: 6389> set "? "FwyOK127.0.0.1: 6389> get "\? "" Fwy"
Exist checks whether the key127.0.0.1: 6389> exists fwy (integer) 1 exist exists.
Del command to delete key 127.0.0.1: 6389> del fwy (integer) 1127.0.0.1: 6389> del fwy (integer) 0 because DEL command does not support wildcards, however, you can use commands such as linux pipelines to delete keys that comply with the rules. Redis-cli keys "users *" | xargs redis-cli del or redis-cli del 'redis-cli keys "user :*"'
Data type for obtaining the key value: type127.0.0.1: 6379> type fwy2string
Dbsize -- return the number of database keys quit to exit
Rename A keyrename fwy fwy3. If fwy3 already exists, it overwrites renamenx fwy fwy3. If fwy3 exists, it will fail to set how many seconds a Key expires, that is, the system automatically deletes the expire fwy3 10ttl and returns the expiration time of a key. The number of seconds is returned. Flushdb: Clear current database data flushall: Clear all database data randomkey: Randomly obtain existing key
Key name: because the key is not a binary safe string, keys containing spaces and line breaks such as "my key" and "mykey \ n" are not allowed.
Redis provides five data types: string, hash, list, set, and sorted setstring, which are the most basic data types of Redis. A single key can store up to 512 MB of data. It stores binary data, so it can contain any data, such as JPG images or serialized objects. Other types are different in the form of organizational strings. For example, the list type organizes strings in the form of a list, and the set type organizes strings in the form of a set.
Set key1 fwy1 -- set the key value. If the key already exists, it will overwrite get key1 -- get the value of key1 setnx key1 fwy1 -- set the value of the Key. If the key already exists, it will fail. Getset key1 value1 first obtains the value of key1, and then sets the value of key1 to value1. If the Key does not exist, nil is returned, but new values are still set. Mget key1 key2 key3 .. if the key does not exist, nilredis 127.0.0.1: 6379> mget fwy4 fwy2 fwy1) "afwe" 2) (nil) 3 is returned) "22" mset fwy4 aaa fwy2 bbb fwy ccc sets the value of multiple keys at a time. msetnx key1 value1 key2 values -- same as above, but does not overwrite the existing value. Incr returns an error for a string whose value is an increment of 1 and is not an integer. If the value does not exist in incr, the value is set to 1. If type is used, the returned type is still string. It only has a function inside it to determine whether the string is a number. Decr is opposite to the above. Incrby key1 5 adds a specified value to the key. If the key does not exist, it is set and the key value is regarded as 0 decrby key1 5. In fact, the above incrby, if the value is negative, the same effect can be achieved. incrbyfloat bus 2.7 adds a double-precision floating point number 127.0.0.1: 6389> incrbyfloat bus 1e + 2 "100" strlen returns the string length 127.0.0.1: 6389> set fwy Hello OK127.0.0.1: 6389> get fwy "\ xe4 \ xbd \ xa0 \ xe5 \ xa5 \ xbd" 127.0.0.1: 6389> strlen fwy (integer) 6Redis received a Chinese character encoded with a UTF-8.
Append can append value to a key. Redis 127.0.0.1: 6379> exists fwy (integer) 0 redis 127.0.0.1: 6379> append fwy "hello" (integer) 6 redis 127.0.0.1: 6379> append fwy "world" (integer) 12 redis 127.0.0.1: 6379> get fwy "hello world" substr seek substrings. An example can prove everything. Redis 127.0.0.1: 6379> set s "This is a string" OKredis 127.0.0.1: 6379> substr s 0 3 "This" redis 127.0.0.1: 6379> substr s-3-1 "ing" redis 127.0.0.1: 6379> substr s 0-1 "This is a string" redis 127.0.0.1: 6379> substr s 9 10000 "string" del Delete keyredis 127.0.0.1: 6379> del fwy4 fwy5 (integer) 1 I here fwy5 does not exist, so only one row is affected
The ASCII code of the set foo barbar3 letter is 114, 97. after being converted to binary, bitwise subscripts of 1100010, 1100001, and 1110010127.0.0.1: 6389> getbit foo 0 (integer) 0127.0.0.1: 6389> getbit foo 6 (integer) 1foo are left to right, starts from 0. If you want to obtain a binary value that exceeds the key, getbit foo 100000 returns the 0. setbit command to set the binary value. The returned value is the old value of this position. For example, we can set the foo key value to aar, set the 6th bits of the Binary Index of the foo key to 0, and set the 7th bits to 1. Setbit foo 6 0 setbit foo 7 1127.0.0.1: 6389> get foo "aar" bitcount foo get the number of bitop commands with 1 binary bits in the string to perform bitwise operations on multiple strings. and, or, xor, not, etc. Set foo1 barset foo2 into bitop or destkey foo1 foo2127.0.0.1: 6389> get destkey "car"