Check the version of Redis

Question:

I’d like to check the version of redis,
it could be accomplished on command line

In [181]: !redis-server --version
Redis server v=4.0.10 sha=00000000:0 malloc=libc bits=64 build=ea14acb2d1b3b56f

However, when it return the redis-py’s version rather than redis version if

In [184]: redis.__version__
Out[184]: '2.10.6

It could be achieved in a wieldy way

In [186]: subprocess.run("redis-server --version", shell=True)
Redis server v=4.0.10 sha=00000000:0 malloc=libc bits=64 build=ea14acb2d1b3b56f
Out[186]: CompletedProcess(args='redis-server --version', returncode=0)

How could I check the version of redis directly with pure code?

Asked By: AbstProcDo

||

Answers:

Redis has the INFO command to get all sort of info about the server:

import redis

r = redis.StrictRedis(host='localhost', port=6379, db=0)
print(r.execute_command('INFO')['redis_version'])
Answered By: ChatterOne

From the cli you can use following command

redis-cli info

Sample Output

# Server
redis_version:4.0.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:f37081b32886670b
redis_mode:standalone
os:Darwin 16.7.0 x86_64
arch_bits:64
multiplexing_api:kqueue
atomicvar_api:atomic-builtin
gcc_version:4.2.1

or if you need version you can try with pipe cmd

redis-cli info | grep "redis_version"

Output

redis_version:4.0.1

i hope this will help

Answered By: Mahesh Hegde

Python Redis has the info function to get all info about redis server.
We can get the redis_version from this function output.

red = redis.Redis(host='localhost', port=6379, db=0)
print(red.info().get('redis_version'))
Answered By: ashok_rajput
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.