Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check the version of Redis

Tags:

python

redis

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?

like image 677
AbstProcDo Avatar asked Dec 24 '22 04:12

AbstProcDo


2 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'])
like image 153
ChatterOne Avatar answered Dec 25 '22 17:12

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

like image 39
Mahesh Hegde Avatar answered Dec 25 '22 18:12

Mahesh Hegde