Bahasa Inggeris [set] Amerika [sɛt]
vt letakkan; Televisyen
adj. Tetap; terletak di...; degil; tersusun
Orang ketiga tunggal: set Plural: set Participle present: setting Kata lampau: set
arahan SET redis sintaks
Fungsi: Kaitkan nilai nilai rentetan dengan kunci . Jika kunci sudah memegang nilai lain, SET akan menimpa nilai lama, tanpa mengira jenis.
Sintaks: SET nilai kunci [EX saat] [PX milisaat] [NX|XX]
Penjelasan: Oleh kerana arahan SET boleh mencapai kesan yang sama seperti tiga arahan SETNX, SETEX dan PSETEX melalui parameter pada masa hadapan Versi Redis mungkin tidak digunakan dan akhirnya mengalih keluar arahan SETNX , SETEX dan PSETEX.
Versi yang tersedia: >= 1.0.0
Kerumitan masa: O(1)
Kembalikan: Sebelum Redis versi 2.6.12 arahan sentiasa dikembalikan, OK Bermula dari Redis versi 2.6.12, SET mengembalikan OK hanya apabila operasi tetapan selesai dengan jayanya. Jika NX atau XX ditetapkan, tetapi operasi tetapan tidak dilaksanakan kerana syarat tidak dipenuhi, arahan mengembalikan Balasan Pukal NULL.
arahan SET redis contoh
# 对不存在的键进行设置 redis 127.0.0.1:6379> SET key "value" OK redis 127.0.0.1:6379> GET key "value" # 对已存在的键进行设置 redis 127.0.0.1:6379> SET key "new-value" OK redis 127.0.0.1:6379> GET key "new-value" # 使用 EX 选项 redis 127.0.0.1:6379> SET key-with-expire-time "hello" EX 10086 OK redis 127.0.0.1:6379> GET key-with-expire-time "hello" redis 127.0.0.1:6379> TTL key-with-expire-time (integer) 10069 # 使用 PX 选项 redis 127.0.0.1:6379> SET key-with-pexpire-time "moto" PX 123321 OK redis 127.0.0.1:6379> GET key-with-pexpire-time "moto" redis 127.0.0.1:6379> PTTL key-with-pexpire-time (integer) 111939 # 使用 NX 选项 redis 127.0.0.1:6379> SET not-exists-key "value" NX OK # 键不存在,设置成功 redis 127.0.0.1:6379> GET not-exists-key "value" redis 127.0.0.1:6379> SET not-exists-key "new-value" NX (nil) # 键已经存在,设置失败 redis 127.0.0.1:6379> GEt not-exists-key "value" # 维持原值不变 # 使用 XX 选项 redis 127.0.0.1:6379> EXISTS exists-key (integer) 0 redis 127.0.0.1:6379> SET exists-key "value" XX (nil) # 因为键不存在,设置失败 redis 127.0.0.1:6379> SET exists-key "value" OK # 先给键设置一个值 redis 127.0.0.1:6379> SET exists-key "new-value" XX OK # 设置新值成功 redis 127.0.0.1:6379> GET exists-key "new-value" # NX 或 XX 可以和 EX 或者 PX 组合使用 redis 127.0.0.1:6379> SET key-with-expire-and-NX "hello" EX 10086 NX OK redis 127.0.0.1:6379> GET key-with-expire-and-NX "hello" redis 127.0.0.1:6379> TTL key-with-expire-and-NX (integer) 10063 redis 127.0.0.1:6379> SET key-with-pexpire-and-XX "old value" OK redis 127.0.0.1:6379> SET key-with-pexpire-and-XX "new value" PX 123321 OK redis 127.0.0.1:6379> GET key-with-pexpire-and-XX "new value" redis 127.0.0.1:6379> PTTL key-with-pexpire-and-XX (integer) 112999 # EX 和 PX 可以同时出现,但后面给出的选项会覆盖前面给出的选项 redis 127.0.0.1:6379> SET key "value" EX 1000 PX 5000000 OK redis 127.0.0.1:6379> TTL key (integer) 4993 # 这是 PX 参数设置的值 redis 127.0.0.1:6379> SET another-key "value" PX 5000000 EX 1000 OK redis 127.0.0.1:6379> TTL another-key (integer) 997 # 这是 EX 参数设置的值