First of all, to install Redis under Windows, the installation package can be found in https://github.com/MSOpenTech/redis/releases, you can download the MSI installation file, or you can download the zip archive.
After downloading the zip file, unzip the files after extracting them:
Inside this Windows Service Documentation.docx is a document that has instructions for installation and how to use it.
You can also download the MSI installation files directly, install them directly, and the files in the installation directory after installation, which can be configured for Redis.
After the installation is complete, you can test Redis, double-click the Redis-cli.exe, and if you do not make an error, you should connect to local Redis for a simple test:
The default installation is Port 6379, and the test is successful.
You can also enter Help to view assistance:
127.0.0.1:6379> Help
REDIS-CLI 3.2.100
To get help about Redis commands type:
' Help @<Group>' to get a list of commands in <Group>
"Help <command>" for Help on <command>
"Help <tab>" to get a list of possible Help topics
"Quit" to exit
To set REDIS-CLI perferences:
": Set hints" Enable online hints
": Set nohints" Disable online hints
Set your preferences in ~/.REDISCLIRC
127.0.0.1:6379> helpredis-cli 3.2.100To Get help about Redis commands type: ' Help @<group> ' to get a list of Commands in <group> ' help <command> ' for ' help ' on <command> ' help <tab> ' to get a list o F Possible Help topics "quit" to Exitto set REDIS-CLI perferences: ": Set hints" Enable online hints ": Set N Ohints "Disable online Hintsset your preferences in ~/.REDISCLIRC
Here's how to use Python for Redis, install Redis using python and install Redis-py Library
1, installation Redis-py
Easy_install Redis can also be installed using PIP install, or https://github.com/andymccurdy/redis-py download and execute Python setup.py Install installation
2, install parser installation
Parser can control how the contents of a Redis response are parsed. Redis-py contains two parser classes, Pythonparser and Hiredisparser. By default, if the Hiredis module is already installed, Redis-py will use Hiredisparser, otherwise pythonparser will be used. Hiredisparser is written in C, and is maintained by the Redis core team, with performance up to 10 times times higher than pythonparser, so it is recommended. Installation method, using Easy_install:
Easy_install Hiredis or pip install Hiredis
3. Using Python to operate Redis
Redis-py provides two classes of Redis and Strictredis for implementing Redis commands, Strictredis is used to implement most of the official commands, and uses the official syntax and commands (for example, the SET command corresponds to the Strictredis.set method). Redis is a subclass of Strictredis for backwards compatibility with older versions of Redis-py.
-
import redis
-
-
R = redis. Strictredis (Host= ' 127.0.0.1 ' , port=6379 )
-
R.set ( ' foo ' , ' hello ' )
-
R.rpush ( ' MyList ' , ' one ' )
-
print r.get ( ' foo ' )
-
print r.rpop ( ' MyList ' )
Import REDISR = Redis. Strictredis (host= ' 127.0.0.1 ', port=6379) r.set (' foo ', ' Hello ') r.rpush (' mylist ', ' one ') print r.get (' foo ') print R.rpop (' MyList ')
Redis-py uses connection pool to manage all connections to a Redis server, avoiding the overhead of each establishment and release of the connection. By default, each Redis instance maintains its own pool of connections. You can create a connection pool directly, and then as a parameter Redis, you can implement multiple Redis instances to share a single connection pool.
-
Pool = redis. ConnectionPool (Host= ' 127.0.0.1 ' , port=6379 )
-
R = redis. Redis (Connection_pool=pool)
-
R.set ( ' one ' , )
-
R.set ( ' n ' , ' second ' )
-
print r.get ( ' one ' )
-
print r.get ( "")
Pool = Redis. ConnectionPool (host= ' 127.0.0.1 ', port=6379) R = Redis. Redis (Connection_pool=pool) r.set (' One ', ' first ') R.set (' Both ', ' second ') Print r.get (' one ') print r.get (' one ')
The Redis pipeline mechanism allows multiple commands to be executed in a single request, thus avoiding multiple round-trip delays.
Pool = Redis. ConnectionPool (host=' 127.0.0.1 ', port=6379)
R = Redis. Redis (Connection_pool=pool)
Pipe = R.pipeline ()
Pipe.set (' One ', ' first ')
Pipe.set (' both ', ' second ')
Pipe.execute ()
Pipe.set (' one '). ' first '). Rpush ('list ', ' Hello '). Rpush (' list ', ' World '). Execute ()
Pool = Redis. ConnectionPool (host= ' 127.0.0.1 ', port=6379) R = Redis. Redis (connection_pool=pool) pipe = R.pipeline () pipe.set (' One ', ' first ') Pipe.set (' One ', ' second ') Pipe.execute () p Ipe.set (' one '). ' first '). Rpush (' list ', ' Hello '). Rpush (' list ', ' World '). Execute ()
Redis-py by default in a single pipeline operation is atomic, to change this way, you can pass in Transaction=false
Pipe = R.pipeline (transaction=False)
Python access to Redis