mirror of
https://github.com/clearlinux/clear-linux-documentation.git
synced 2026-04-29 11:38:23 +00:00
320 lines
16 KiB
HTML
320 lines
16 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html lang="en" data-content_root="../">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
||
<title>Redis* — Documentation for Clear Linux* project</title>
|
||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/bizstyle.css?v=5283bb3d" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
|
||
|
||
<script src="../_static/documentation_options.js?v=5929fcd5"></script>
|
||
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
|
||
<script src="../_static/copybutton.js?v=a56c686a"></script>
|
||
<script src="../_static/bizstyle.js"></script>
|
||
<link rel="canonical" href="https://clearlinux.github.io/clear-linux-documentation/tutorials/redis.html" />
|
||
<link rel="icon" href="../_static/favicon.ico"/>
|
||
<link rel="author" title="About these documents" href="../about.html" />
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="Samba* as a client" href="smb-desktop.html" />
|
||
<link rel="prev" title="PHP and PHP-FPM" href="php.html" />
|
||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||
<!--[if lt IE 9]>
|
||
<script src="_static/css3-mediaqueries.js"></script>
|
||
<![endif]-->
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="smb-desktop.html" title="Samba* as a client"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="php.html" title="PHP and PHP-FPM"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Documentation for Clear Linux* project</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Tutorials</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Redis*</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="redis">
|
||
<span id="id1"></span><h1>Redis*<a class="headerlink" href="#redis" title="Link to this heading">¶</a></h1>
|
||
<p>In this tutorial, you’ll install <abbr title="REmote DIctionary Server">Redis</abbr>
|
||
and launch a <cite>Redis-server</cite> on Clear Linux* OS. We invite you to pull our
|
||
<a class="reference external" href="https://hub.docker.com/r/clearlinux/redis">Clear Linux Redis instance</a> on Docker Hub* for application or
|
||
infrastructure development.</p>
|
||
<nav class="contents local" id="contents">
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#description" id="id2">Description</a></p></li>
|
||
<li><p><a class="reference internal" href="#install-the-redis-bundle" id="id3">Install the Redis bundle</a></p></li>
|
||
<li><p><a class="reference internal" href="#start-the-redis-server" id="id4">Start the Redis-server</a></p></li>
|
||
<li><p><a class="reference internal" href="#example-1-use-the-redis-cli-and-commands" id="id5">Example 1: Use the redis-cli and commands</a></p></li>
|
||
<li><p><a class="reference internal" href="#example-2-run-the-cl-redis-docker-image" id="id6">Example 2: Run the Clear Linux OS Redis Docker* image</a></p></li>
|
||
<li><p><a class="reference internal" href="#next-steps" id="id7">Next Steps</a></p></li>
|
||
</ul>
|
||
</nav>
|
||
<section id="description">
|
||
<h2><a class="toc-backref" href="#id2" role="doc-backlink">Description</a><a class="headerlink" href="#description" title="Link to this heading">¶</a></h2>
|
||
<p>Redis is an in-memory key:value store designed for quick lookups, accessible
|
||
over a network. While the <a class="reference external" href="https://redis.io/">redis data structure store</a> can serve
|
||
as a NoSQL database for a web application, it’s also easy to integrate into an
|
||
existing stack. For example, you could use the Redis caching layer for
|
||
real-time responses on a leaderboard in a gaming app. Redis offers many client
|
||
libraries with language-specific bindings for Python*, Perl*, Ruby, and more.</p>
|
||
</section>
|
||
<section id="install-the-redis-bundle">
|
||
<h2><a class="toc-backref" href="#id3" role="doc-backlink">Install the Redis bundle</a><a class="headerlink" href="#install-the-redis-bundle" title="Link to this heading">¶</a></h2>
|
||
<ol class="arabic">
|
||
<li><p>Log in as a user with administrative privilege.</p></li>
|
||
<li><p>Open a terminal.</p></li>
|
||
<li><p>Update your Clear Linux OS to the latest version.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>swupd<span class="w"> </span>update
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Install the <cite>redis-native</cite> bundle.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>swupd<span class="w"> </span>bundle-add<span class="w"> </span>redis-native
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
</ol>
|
||
</section>
|
||
<section id="start-the-redis-server">
|
||
<h2><a class="toc-backref" href="#id4" role="doc-backlink">Start the Redis-server</a><a class="headerlink" href="#start-the-redis-server" title="Link to this heading">¶</a></h2>
|
||
<p>A <strong class="command">systemd</strong> service unit is available to control the Redis-server.
|
||
By default, Redis runs on port 6379.</p>
|
||
<ol class="arabic">
|
||
<li><p>Start the service and set it to start automatically on boot.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>systemctl<span class="w"> </span><span class="nb">enable</span><span class="w"> </span>--now<span class="w"> </span>redis
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Confirm the service is running.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>systemctl<span class="w"> </span>status<span class="w"> </span>redis
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Verify that the Redis-server sends a reply.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>redis-cli<span class="w"> </span>ping
|
||
</pre></div>
|
||
</div>
|
||
<p>Expected output:</p>
|
||
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">PONG</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
</ol>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>If you wish to customize settings for Redis, copy the
|
||
default <code class="file docutils literal notranslate"><span class="pre">/usr/share/defaults/etc/redis.conf</span></code> file into the
|
||
/etc/ directory, make changes as needed, and restart the service.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>cp<span class="w"> </span>-v<span class="w"> </span>/usr/share/defaults/etc/redis.conf<span class="w"> </span>/etc/
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<p>The Redis-server is now ready to use on Clear Linux OS. Try some of the examples shown
|
||
below.</p>
|
||
</section>
|
||
<section id="example-1-use-the-redis-cli-and-commands">
|
||
<h2><a class="toc-backref" href="#id5" role="doc-backlink">Example 1: Use the redis-cli and commands</a><a class="headerlink" href="#example-1-use-the-redis-cli-and-commands" title="Link to this heading">¶</a></h2>
|
||
<p>One advantage of Redis over other NoSQL databases is that developers can
|
||
easily access data structures like lists, sets, sorted sets, strings, and
|
||
hashes using collection operations commands similar to those found in many
|
||
programming languages. These exercises are inspired by <a class="reference external" href="http://try.redis.io/">try redis io</a>.</p>
|
||
<p>After your Redis-server is running, try some basic commands.</p>
|
||
<ol class="arabic">
|
||
<li><p>Start <cite>redis-cli</cite>. It provides syntax suggestions as you type.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>redis-cli
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p><strong class="command">SET</strong> a key to hold a string value. In the set, create connections
|
||
and increment.</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>SET server:name "clearlinux"
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>MGET server:name
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>If the key does not exist or hold a key value, <cite>nil</cite> is returned.</p>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>SET connections 100
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>INCR connections
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>INCR connections
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>DEL connections
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Create a <cite>friends</cite> list and insert new values at the end of the list.</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>RPUSH friends "Deb"
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>RPUSH friends "David"
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>RPUSH friends "Mary"
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Modify the <cite>friends</cite> list, using a common slice method with a 0-index.</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>LRANGE friends 0 1
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>LLEN friends
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>LPOP friends
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>RPOP friends
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>LLEN friends
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
<li><p>Consider using a hash, which maps string fields and string values, and
|
||
offers multiple lookup methods.</p>
|
||
<p>Enter many user key:values with <cite>HMSET</cite>. Then try <cite>HGET</cite> and <cite>HGETALL</cite>.</p>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>HMSET user:1000 name "Robert Noyce" password "SuperEngi9eer" email "robert.noyce@intel.com"
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>HGET user:1000 name
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>HGET user:1000 email
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>HGETALL user:1000
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
</ol>
|
||
</section>
|
||
<section id="example-2-run-the-cl-redis-docker-image">
|
||
<h2><a class="toc-backref" href="#id6" role="doc-backlink">Example 2: Run the Clear Linux OS Redis Docker* image</a><a class="headerlink" href="#example-2-run-the-cl-redis-docker-image" title="Link to this heading">¶</a></h2>
|
||
<p>We also provide a <a class="reference external" href="https://hub.docker.com/r/clearlinux/redis">Clear Linux Redis instance</a>, which is
|
||
updated continuously and maintained by Clear Linux OS development.</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>swupd<span class="w"> </span>bundle-add<span class="w"> </span>containers-basic
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>systemctl<span class="w"> </span>start<span class="w"> </span>docker
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>-E<span class="w"> </span>docker<span class="w"> </span>pull<span class="w"> </span>clearlinux/redis
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="next-steps">
|
||
<h2><a class="toc-backref" href="#id7" role="doc-backlink">Next Steps</a><a class="headerlink" href="#next-steps" title="Link to this heading">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>Follow the <a class="reference external" href="https://redis.io/topics/quickstart">redis quickstart tutorial</a> to expand potential uses.</p></li>
|
||
<li><p>Learn how to use <a class="reference internal" href="docker.html#docker"><span class="std std-ref">Docker*</span></a>.</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="Main">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../_static/clearlinux.png" alt="Logo of Clear Linux* Project Docs"/>
|
||
</a></p>
|
||
<div>
|
||
<h3><a href="../index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">Redis*</a><ul>
|
||
<li><a class="reference internal" href="#description">Description</a></li>
|
||
<li><a class="reference internal" href="#install-the-redis-bundle">Install the Redis bundle</a></li>
|
||
<li><a class="reference internal" href="#start-the-redis-server">Start the Redis-server</a></li>
|
||
<li><a class="reference internal" href="#example-1-use-the-redis-cli-and-commands">Example 1: Use the redis-cli and commands</a></li>
|
||
<li><a class="reference internal" href="#example-2-run-the-cl-redis-docker-image">Example 2: Run the Clear Linux OS Redis Docker* image</a></li>
|
||
<li><a class="reference internal" href="#next-steps">Next Steps</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="php.html"
|
||
title="previous chapter">PHP and PHP-FPM</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="smb-desktop.html"
|
||
title="next chapter">Samba* as a client</a></p>
|
||
</div>
|
||
<div role="note" aria-label="source link">
|
||
<h3>This Page</h3>
|
||
<ul class="this-page-menu">
|
||
<li><a href="../_sources/tutorials/redis.rst.txt"
|
||
rel="nofollow">Show Source</a></li>
|
||
</ul>
|
||
</div>
|
||
<search id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</search>
|
||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="smb-desktop.html" title="Samba* as a client"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="php.html" title="PHP and PHP-FPM"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Documentation for Clear Linux* project</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Tutorials</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Redis*</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2022 Intel Corporation. All Rights Reserved..
|
||
Last updated on Nov 04, 2024.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
|
||
</div>
|
||
</body>
|
||
</html> |