Redis - Create key using the redis-cli
by
Jeremy Canfield |
Updated: April 15 2024
| Redis articles
If you don't have the Redis CLI installed, check out my article Install redis-cli from source.
This assumes you are able to connect to Redis using the redis-cli. If not, check out my article Connect to Redis using the redis-cli.
If the connection is successful, you should get an interactive redis command prompt. The keys command can be used to display all of the current keys.
~]$ redis-cli -h redis.example.com -p 6379
redis.example.com:6379> keys *
1) "foo"
2) "bar"
The set command can be used to create a new key.
redis.example.com:6379> set greeting "hello world"
OK
redis.example.com:6379> keys *
1) "foo"
2) "bar"
3) "greeting"
redis.example.com:6379> keys greeting
1) "hello world"
Often, you'll want to expire the key after a period of time. In this example, the greeting key will expire in 60 seconds.
my-redis-cluster.2wfrq3.clustercfg.use1.cache.amazonaws.com:6379> set greeting "hello world" EX 60
OK
Did you find this article helpful?
If so, consider buying me a coffee over at