1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta http-equiv ="Content-Type " content ="text/html; charset=UTF-8 ">
5+ < meta charset ="utf-8 ">
6+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8+ < meta name ="author " content ="Matt Makai ">
9+ < meta name ="description " content ="Step-by-step instructions to install Redis and use it with Python 3 and redis-py on Ubuntu 16.04 Xenial Xerus. ">
10+ < link rel ="shortcut icon " href ="/img/fsp-fav.png ">
11+ < title > Installing Redis to use with Python 3 and redis-py on Ubuntu 16.04 - Full Stack Python</ title >
12+ <!--[if lt IE 9]>
13+ <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
14+ <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
15+ <![endif]-->
16+ < link href ="/theme/css/f.min.css " rel ="stylesheet ">
17+ </ head >
18+ < body >
19+ < a href ="https://github.com/makaimc/fullstackpython.com "> < img style ="position: absolute; top: 0; right: 0; border: 0; " src ="/img/fork.png " alt ="Fork me on GitHub "> </ a >
20+ < div class ="container ">
21+ < div class ="row ">
22+ < div class ="col-md-12 ">
23+ < div class ="logo-header-section ">
24+ < a href ="/ " style ="text-decoration: none; border: none; "> < img src ="/theme/img/logo.png " height ="52 " width ="52 " class ="logo-image " style ="padding-top: 1px; " alt ="Full Stack Python logo "> </ a >
25+ < span class ="logo-title "> < a href ="https://www.fullstackpython.com/ "> Full Stack Python</ a > </ span >
26+ </ div >
27+ < div class ="subnav ">
28+ <!--<a href="/blog.html" class="submenu-item-first">Blog</a> |
29+ <a href="/books.html" class="submenu-item">Books</a> | -->
30+ < a href ="/table-of-contents.html " class ="submenu-item-first "> All topics</ a > |
31+ < a href ="/blog.html " class ="submenu-item "> Blog</ a > |
32+ < a href ="/email.html " class ="submenu-item "> Newsletter</ a > |
33+ < a href ="https://twitter.com/fullstackpython " class ="submenu-item "> @fullstackpython</ a > |
34+ < a href ="https://www.facebook.com/fullstackpython " class ="submenu-item "> Facebook</ a > |
35+ < a href ="https://github.com/makaimc/fullstackpython.com/tree/gh-pages/source " class ="submenu-item "> Source</ a >
36+ </ div > </ div >
37+ </ div > < div class ="row ">
38+ < div class ="col-md-12 ">
39+ < h1 class ="blog-h1 "> Installing Redis to use with Python 3 and redis-py on Ubuntu 16.04</ h1 >
40+ < div class ="post-byline ">
41+ Posted by < a href ="/about-author.html "> Matt Makai</ a > on
42+ May 16, 2016.
43+ </ div >
44+ < p > < a href ="http://redis.io "> Redis</ a > is an in-memory key-value pair
45+ < a href ="/no-sql-datastore.html "> NoSQL data store</ a > often used in Python applications
46+ for < a href ="/web-frameworks.html "> web application</ a > sessions and caching,
47+ transient < a href ="/data.html "> data</ a > storage and as a broker for
48+ < a href ="/task-queues.html "> task queues</ a > .
49+ < a href ="https://pypi.python.org/pypi/redis "> redis-py</ a > is a common Python code
50+ library for interacting with Redis. Let's learn how to get Redis up
51+ and running on Ubuntu and then start using it in a simple Python application.</ p >
52+ < h2 > Tools We Need</ h2 >
53+ < p > This tutorial is tested with Python 3.5 but either
54+ < a href ="/python-2-or-3.html "> Python 2 or 3</ a > should work for everything written
55+ here. Just make sure one version is installed on your system by going to
56+ the terminal and typing < code > python --version</ code > .</ p >
57+ < ul >
58+ < li > Python 3</ li >
59+ < li > < a href ="https://pip.pypa.io/en/stable/ "> pip</ a > and
60+ < a href ="https://virtualenv.pypa.io/en/latest/ "> virtualenv</ a > to handle the
61+ redis-py < a href ="/application-dependencies.html "> application dependency</ a > </ li >
62+ </ ul >
63+ < p > If you aren't sure how how to install pip and virtualenv, review the
64+ first few steps of the
65+ < a href ="/blog/python-3-flask-green-unicorn-ubuntu-1604-xenial-xerus.html "> how to set up Python 3, Flask and Green Unicorn on Ubuntu 16.04 LTS</ a >
66+ guide.</ p >
67+ < h2 > Install Redis</ h2 >
68+ < p > There are a few ways to install Redis, such as
69+ < a href ="http://redis.io/topics/quickstart "> downloading and compiling from source</ a > .
70+ However, on Ubuntu we can install a system package through < code > apt</ code > . The
71+ advantage of this method is that the < code > apt</ code > process will take care of
72+ installing < code > redis-server</ code > as a system service. Open the terminal and run
73+ the following command:</ p >
74+ < div class ="highlight "> < pre > sudo apt-get install redis-server
75+ </ pre > </ div >
76+
77+
78+ < p > When you're prompted whether you want to install the new package enter
79+ 'yes'.</ p >
80+ < p > < img src ="/source/static/img/160516-redis-ubuntu-1604/apt-get-redis.png " width ="100% " class ="technical-diagram img-rounded "> </ p >
81+ < p > After a few moments the downloading and processing should be complete
82+ and you will be back at the prompt.</ p >
83+ < p > < img src ="/source/static/img/160516-redis-ubuntu-1604/apt-get-redis.png " width ="100% " class ="technical-diagram img-rounded "> </ p >
84+ < p > Redis is now installed. Even though we installed the < code > redis-server</ code > package,
85+ the installation also comes with the Redis command line client. The client
86+ is useful for connecting directly to the Redis server without any Python
87+ code. Give < code > redis-cli</ code > a try by typing this into the command prompt:</ p >
88+ < div class ="highlight "> < pre > redis-cli
89+ </ pre > </ div >
90+
91+
92+ < p > < img src ="/source/static/img/160516-redis-ubuntu-1604/redis-cli.png " width ="100% " class ="technical-diagram img-rounded "> </ p >
93+ < h2 > Install redis-py</ h2 >
94+ < h2 > Working with Redis from Python</ h2 >
95+ < p > Questions? Tweet < a href ="https://twitter.com/fullstackpython "> @fullstackpython</ a >
96+ or post a message on the
97+ < a href ="https://www.facebook.com/fullstackpython "> Full Stack Python Facebook page</ a > .
98+ Something wrong with this post? Fork
99+ < a href ="https://github.com/makaimc/fullstackpython.com/blob/gh-pages/source/content/posts/160516-install-redis-use-python-3-ubuntu-1604.markdown "> this page's source on GitHub</ a > .</ p >
100+ < hr >
101+ < div id ="mc_embed_signup ">
102+ < form action ="//mattmakai.us2.list-manage.com/subscribe/post?u=b7e774f0c4f05dcebbfee183d&id=b22335388d " method ="post " id ="mc-embedded-subscribe-form " name ="mc-embedded-subscribe-form " class ="validate " target ="_blank " novalidate >
103+ < div id ="mc_embed_signup_scroll ">
104+ < h4 > Sign up here to receive a monthly email with major updates to this site, tutorials and discount codes for Python books.</ h4 >
105+ < div class ="row ">
106+ < div class ="col-md-9 ">
107+ < input type ="email " value ="" name ="EMAIL " class ="email form-control " id ="mce-EMAIL " placeholder ="email address " required >
108+ < div style ="position: absolute; left: -5000px; "> < input type ="text " name ="b_b7e774f0c4f05dcebbfee183d_b22335388d " tabindex ="-1 " value =""> </ div >
109+ </ div >
110+ < div class ="col-md-3 ">
111+ < div class ="clear "> < input type ="submit " value ="Subscribe " name ="subscribe " id ="mc-embedded-subscribe " class ="btn btn-success " style ="font-family: 'Helvetica Neue'; "> </ div >
112+ </ div >
113+ </ div >
114+ </ div >
115+ </ form >
116+ </ div >
117+ </ div >
118+ </ div >
119+ < hr />
120+ </ div >
121+ < div style ="padding: 0 0 20px 0; margin: 0 0 20px 0; background-color: #22B24C; ">
122+ < div class ="container ">
123+ < p class ="banner "> < a href ="https://www.gumroad.com/l/python-deployments " style ="color: #fff "> Learning web development? Check out The Full Stack Python Guide to Deployments book</ a > !</ p >
124+ </ div >
125+ </ div > < div class ="container ">
126+ < div class ="footer pull-right ">
127+ < a href ="http://www.mattmakai.com/ " class ="underline "> Matt Makai</ a >
128+ 2016
129+ </ div >
130+ </ div >
131+ < script >
132+ ( function ( i , s , o , g , r , a , m ) { i [ 'GoogleAnalyticsObject' ] = r ; i [ r ] = i [ r ] || function ( ) {
133+ ( i [ r ] . q = i [ r ] . q || [ ] ) . push ( arguments ) } , i [ r ] . l = 1 * new Date ( ) ; a = s . createElement ( o ) ,
134+ m = s . getElementsByTagName ( o ) [ 0 ] ; a . async = 1 ; a . src = g ; m . parentNode . insertBefore ( a , m )
135+ } ) ( window , document , 'script' , '//www.google-analytics.com/analytics.js' , 'ga' ) ;
136+ ga ( 'create' , 'UA-19910497-7' , 'auto' ) ;
137+ ga ( 'send' , 'pageview' ) ;
138+ </ script >
139+
140+ < script type ='text/javascript '>
141+ var trackOutboundLink = function ( url ) { ga ( 'send' , 'event' , 'outbound' , 'click' , url , { 'hitCallback' : function ( ) { document . location = url ; } } ) ; }
142+ </ script >
143+ </ body >
144+ </ html >
0 commit comments