How to use Python Redis

Source: Internet
Author: User
Tags install redis redis server

One, the Mac under Redis installation

1. Brew Installation Redis

Brew Install Redis

2. Start Redis Server

Brew Services Start Redis

Or

Redis-server/usr/local/etc/redis.conf

Second, Python operation Redis

1. Connection mode

Redis-py provides two classes of Redis and Strictredis for implementing Redis commands, Strictredis is used to implement most of the official commands, and using official syntax and commands, Redis is a subclass of Strictredis

#!/usr/bin/env python#-*-coding:utf-8-*-import redisr = Redis. Redis (host= ' 192.168.0.110 ', port=6379,db=0) r.set (' name ', ' Zhangsan ')   #添加print (r.get (' name '))   #获取

2. Connection Pool

  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.

#!/usr/bin/env python#-*-coding:utf-8-*-import redispool = Redis. ConnectionPool (host= ' 192.168.0.110 ', port=6379) R = Redis. Redis (Connection_pool=pool) r.set (' name ', ' Zhangsan ')   #添加print (r.get (' name '))   #获取

How to use Python Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.