Redis 简明教程
Redis - Strings
Redis 字符串命令用于管理 Redis 中的字符串值。以下是使用 Redis 字符串命令的语法。
Redis strings commands are used for managing string values in Redis. Following is the syntax for using Redis string commands.
Example
redis 127.0.0.1:6379> SET tutorialspoint redis
OK
redis 127.0.0.1:6379> GET tutorialspoint
"redis"
在上述示例中, SET 和 GET 是命令,而 tutorialspoint 是密钥。
In the above example, SET and GET are the commands, while tutorialspoint is the key.
Redis Strings Commands
下表列出了管理 Redis 中字符串的一些基本命令。
Following table lists some basic commands to manage strings in Redis.
Sr.No |
Command & Description |
1 |
SET key valueThis command sets the value at the specified key. |
2 |
GET keyGets the value of a key. |
3 |
GETRANGE key start endGets a substring of the string stored at a key. |
4 |
GETSET key value Sets the string value of a key and return its old value. |
5 |
GETBIT key offsetReturns the bit value at the offset in the string value stored at the key. |
6 |
MGET key1 [key2..]Gets the values of all the given keys |
7 |
SETBIT key offset value Sets or clears the bit at the offset in the string value stored at the key |
8 |
SETEX key seconds valueSets the value with the expiry of a key |
9 |
SETNX key valueSets the value of a key, only if the key does not exist |
10 |
SETRANGE key offset valueOverwrites the part of a string at the key starting at the specified offset |
11 |
STRLEN keyGets the length of the value stored in a key |
12 |
MSET key value [key value …]Sets multiple keys to multiple values |
13 |
MSETNX key value [key value …]Sets multiple keys to multiple values, only if none of the keys exist |
14 |
PSETEX key milliseconds valueSets the value and expiration in milliseconds of a key |
15 |
INCR keyIncrements the integer value of a key by one |
16 |
INCRBY key incrementIncrements the integer value of a key by the given amount |
17 |
INCRBYFLOAT key incrementIncrements the float value of a key by the given amount |
18 |
DECR keyDecrements the integer value of a key by one |
19 |
DECRBY key decrementDecrements the integer value of a key by the given number |
20 |
APPEND key valueAppends a value to a key |