Redis的底层类型之string

werbenhu / 122 / 2023-09-25 11:22:12

ChatGPT 可用网址,仅供交流学习使用,如对您有所帮助,请收藏并推荐给需要的朋友。
https://ckai.xyz

string

  • SET

stores a string value.

SET key value [NX | XX] [GET] [EX seconds | PX milliseconds |
  EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]

KEEPTTL: 用于在使用 SET 命令设置键的值时,保留键的 TTL(Time To Live)信息。当你使用 SET 命令来更新一个已经存在的键时,默认情况下会重置键的 TTL,也就是键的生存时间会被重新计算。但是如果你希望保留原有的 TTL,可以使用 KEEPTTL 选项。

  • SETEX

等价于 SET key value EX seconds

  • PSETEX

PSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds. 跟SETEX类似,区别就是这个是毫秒。

  • SETNX

stores a string value only if the key doesn't already exist. Useful for implementing locks.

  • GET

retrieves a string value.

  • GETDEL

Get the value of key and delete the key.

  • GETSET

Atomically sets key to value and returns the old value stored at key.

  • GETEX

Get the value of key and optionally set its expiration.获取键的值,并且同时可以为该键设置新的过期时间

  • MGET

retrieves multiple string values in a single operation.

  • SUBSTR

SUBSTR key start end

Returns the substring of the string value stored at key. 现在已被弃用,不推荐在新的应用程序中使用。相反,您应该使用 GETRANGE 命令来执行类似的操作

  • GETRANGE

GETRANGE key start end

Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).

  • STRLEN

Returns the length of the string value stored at key.

  • APPEND

APPEND key value

If key already exists and is a string, this command appends the value at the end of the string. If key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.

  • INCR

Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.

  • DECR
  • INCRBY
  • DECRBY
  • INCRBYFLOAT
  • DECRBYFLOAT

作者
werbenhu
许可协议
CC BY 4.0
发布于
2023-09-25
修改于
2024-05-27
Bonnie image
尚未登录