Skip to content

Instantly share code, notes, and snippets.

@vanushwashere
Last active July 26, 2022 21:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanushwashere/7c069da39923fbce9d1a3005cbe5c418 to your computer and use it in GitHub Desktop.
Save vanushwashere/7c069da39923fbce9d1a3005cbe5c418 to your computer and use it in GitHub Desktop.
Redis CLI most used and basic commands

Source

https://habrahabr.ru/post/204354/

Authentication

bash> redis-cli -h 127.0.0.1 -p 6379 -a mysupersecretpassword //with ip bash> redis-cli -s /tmp/redis.sock -p 6379 -a mysupersecretpassword //with socket

or

redis> AUTH mysupersecretpassword

Working with Key Values

Set Value

redis> set test:1:string "my binary safe string" OK

Get Value

redis> get test:1:string "my binary safe string"

Set if not get

redis> getset test:1:string "other value" "my binary safe string"

Get type of var

redis> type test:1:string string

Rename key of var

redis> rename test:1:vlaue test:1:value
OK

Check for existence

redis> exists test:1:value (integer) 1

Get keys

redis> keys test:1:*

  1. "test:1:string"
  2. "test:1:value"

Delete by key

redis> del test:1:value (integer) 1

TTL (Time to live)

Get TTL

redis> ttl test:1:string (integer) -1

Set TTL

redis> expire test:1:string 6000 (integer) 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment