Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Redis

Redis HINCRBYFLOAT: เพิ่มค่า Floating-Point ใน Hash Field แบบขั้นตอน

ในบทเรียนนี้ เราจะเรียนรู้วิธีการเพิ่มค่า floating-point number ที่เก็บอยู่ใน field ภายใน Hash value ที่เก็บใน key ใน Redis datastore โดยใช้คำสั่ง HINCRBYFLOAT ใน redis-cli

คำสั่งนี้ใช้เพิ่มค่า floating-point number ที่เก็บอยู่ใน field ที่ระบุ ใน Hash value ที่เก็บใน key ด้วยค่าที่ระบุ (increment) หาก field ที่ระบุไม่มีอยู่ใน Hash value จะถูกเพิ่มเข้าไปพร้อมกับค่า increment เป็นค่าเริ่มต้น หาก key ไม่มีอยู่ Hash value ใหม่จะถูกสร้างขึ้นพร้อมกับ field ที่ระบุเป็นสมาชิกเดียว หากส่งค่า floating-point แบบลบเป็นอาร์กิวเมนต์ ค่า field จะถูกลดลงแทนที่จะเพิ่มขึ้น

จะคืนค่า error หาก key มีอยู่แต่ค่าที่เก็บไม่ใช่ Hash datatype หรือหากค่า field หรือค่า increment ที่ระบุไม่ใช่ double precision floating-point number

Syntax

redis host:port> HINCRBYFLOAT <keyname> <field> <increment>

Output

- (string) reply: แสดงค่าใหม่ที่เก็บใน field
- Error: หาก key มีอยู่แต่ค่าที่เก็บไม่ใช่ Hash

ตัวอย่าง

Redis HINCRBYFLOAT: เพิ่มค่า Floating-Point ใน Hash Field แบบขั้นตอน

อ้างอิง

  1. HINCRBYFLOAT Command Docs

ขอจบบทเรียนสำหรับวิธีเพิ่มค่า floating-point number ใน field ของ Hash value ที่เก็บใน Redis datastore หากชอบบทเรียนนี้ กรุณาแบ่งปันความคิดเห็นและแชร์ให้ผู้อื่นด้วยครับ