Skip to main content
Version: 1.7.2

Simulating expiring the key in redis

Introduction

An experiment that simulates expiring the key in redis by modifying the key expiration time。

CLI Command

  • blade create redis cache-expire -h

Parameter

NameIntroductionTypeRequiredExample Value
addrThe address of redis server, the format is ip:port.stringY192.168.56.101:6379
passwordThe password of redis server.stringY123456
keyThe key to be set an expiry, default expires all keys. The default value is "".stringNtest1
expiryThe expiry of the key. An expiry string should be able to be converted to a time duration, such as "5s" or "30m".stringY10s
optionThe additional options of expiry, only NX, XX, GT, LT supported.stringNGT

Case

# Set the expiration time to 1 minute.
# blade create redis cache-expire --addr 192.168.56.101:6379 --password 123456 --key test1 --expiry 1m
{"code":200,"success":true,"result":"b6a0f477b7fb1f4c"}

# Set the expiration time when the new expiration time is greater than current one.
# blade create redis cache-expire --addr 192.168.56.101:6379 --password 123456 --key test1 --option GT --expiry 1m
{"code":200,"success":true,"result":"b6a0f477b7fb1f4c"}

Principle

Modify the expiration time by using Golang interface in go-redis package.

Q&A

Q: {"code":44000,"success":false,"error":"parse duration error: time: missing unit in duration \"1\": action not supported"}

A: An expiry string should be able to be converted to a time duration, such as "5s" or "30m".