Learn Basic Redis Commands

Category : Redis

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kinds of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes, HyperLogLogs, Bitmaps.

We wrote a few guides on Redis in past few months. You can find them in our Redis blog category here. Today we will show you some basic Redis Commands that will be helpful when working on Redis.

  • Start redis with the related configuration file from SSH
    redis-server /path/redis.conf
  • Open a redis prompt from SSH
    redis-cli

Redis Log Location /var/log/
Redis Log File – redis.log or redis_portnumber.log

  • Check configuration loaded on redis-server
    cat /var/log/redis_6379.log | grep Configuration
    The output will be as the following image.redis log output
    Here you can check timings when you stared redis-server and see if logs have the “Configuration Loaded”. If configuration loaded
    You can use nano to manually view full log.
    nano /var/log/redis_6379.log

Below Commands Should be run inside redis-cli

  • Check Redis Server status
    PING
    The output should be ‘PONG’ if server status is active
  • Set value in the key
    SET key value
  • Get value in the key
    GET key
  • Get the length of the value stored in a key
    STRLEN key
  • Increment value in the key
    INCR key
  • Increment the integer value of a key by the given amount
    INCRBY key increment
  • Decrement the integer value of the key by one
    DECR key
  • Decrement the integer value of a key by the given number
    DECRBY key decrement
  • Delete key
    DEL key
  • List of all active configuration variables you can change
    CONFIG GET *
  • Get the value of maxmemory configuration for Redis
    CONFIG GET maxmemory
  • Get the value of dbfilename
    CONFIG GET dbfilename
  • Change key by issuing a “CONFIG SET” command like
    CONFIG SET timeout 500
    500 is new value
  • Change the key value for maxmemory
    CONFIG SET maxmemory 4157683648
    4157683648 is new value
  • Check the number of keys in the database.
    DBSIZE
  • Check if a key exists
    EXISTS key
    Output will be in 0 or 1
    Here, 0 and: 1 mean false and true, respectively.
  • Purge all of the keys from the database
    FLUSH DB
  • Close both Redis and our telnet session
    SHUTDOWN