美文网首页
linux安装redis

linux安装redis

作者: 东方舵手 | 来源:发表于2018-09-02 20:57 被阅读0次
  1. 上传并解压


    Redis是c语言开发的 安装redis需要c语言的便宜环境。如果没有gcc需要在线安装。yum install gcc-c++
  2. 编译。进入redis源码目录。 make 命令

[root@oym redis-3.0.0]# make
  1. 安装。make install PREFIX=/usr/local/redis,PREFIX参数指定redis的安装目录。一般软件安装到/usr目录下
[root@oym redis-3.0.0]# make install PREFIX=/usr/local/redis
  1. redis的启动
    4.1 前端启动 : 在redis的安装目录下直接启动redis-server
[root@oym redis-3.0.0]# cd /usr/local/redis/bin
[root@oym bin]# ./redis-server

4.2 后端启动

# 把/root/redis-3.0.0/redis.conf复制到/usr/local/redis/bin目录下
[root@oym bin]# cp ~/redis-3.0.0/redis.conf .

修改redis.conf


# 启动redis
[root@localhost bin]# ./redis-server redis.conf

# 查看redis进程:
[root@localhost bin]# ps aux|grep redis
root      5190  0.1  0.3  33936  1712 ?        Ssl  18:23   0:00 ./redis-server *:6379    
root      5196  0.0  0.1   4356   728 pts/0    S+   18:24   0:00 grep redis

Redis-cli

[root@localhost bin]# ./redis-cli 
默认连接localhost运行在6379端口的redis服务。
[root@localhost bin]# ./redis-cli -h 192.168.25.153 -p 6379
-h:连接的服务器的地址
-p:服务的端口号

关闭redis:[root@localhost bin]# ./redis-cli shutdown

redis的五种数据类型
string , hash , list , set , SortedSet(zet)

redis的简单操作

命令 作用
set str1 123 保存一个key的值
get str1 获取一个key的值
incr str1 使key的值自增
decr str1 使key的值自减
hset hash1 field1 123 保存hash类型的key
hget hash1 field1 获取hash类型的key
ttl key 查看key的有效期 -1永久保存,-2保存在,整数有效期倒数然后删除key
expire key 100 设置key的有效期
keys * 查看当前数据库的所有key

二 java总使用Jedis

  1. 引入pom依赖
    <!-- Redis客户端 -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <jedis.version>2.7.2</jedis.version>
        </dependency>

2 . test例子

public class TestJedis {

    @Test
    public void testJedis() {
        //创建一个jedis对象,需要指定服务的ip和端口号
        Jedis jedis = new Jedis("192.168.66.124",6379);
        //直接操作数据库
        jedis.set("jedis-key", "1234");
        String result = jedis.get("jedis-key");
        System.out.println(result);
        //关闭jedis
        jedis.close();
    }
    
    @Test
    public void testJedisPool() throws Exception {
        //创建一个数据库连接池对象(单例),需要指定服务额ip和端口号
        JedisPool jedisPool = new JedisPool("192.168.66.124",6379);
        //从连接池中获得链接
        Jedis jedis = jedisPool.getResource();
        //使用jedis操作数据库(方法级别使用)
        String str = jedis.get("jedis-key");
        System.out.println(str);
        //一定要关闭jedis链接
        jedis.close();
        //系统关闭前关闭连接池
        jedisPool.close();
    }
    
}

相关文章

  • 记一次搭建生产服务器

    Linux JDK 安装 Linux Maven 安装 Linux node 安装 Linux redis安装 L...

  • linux redis 安装及基本配置

    每次 linux redis安装,都要百度,索性将 linux redis 源码安装及配置记下,含 redis ...

  • Linux 安装

    Linux下安装mysql CentOS7.x系统安装Redis6.0.1 Linux安装redis和部署 Red...

  • redis

    linux安装redis

  • redis操作小结

    安装redis(windows、Linux、Ubuntu和Mac):Redis 安装 redis的启动、连接、停止...

  • linux下安装redis

    linux下的redis安装 1.首先将redis安装包下载到linux系统 redis官网https://red...

  • linux redis

    linux 安装redis wget http://download.redis.io/redis-stable....

  • 六. Redis集群

    一. Linux中Redis的安装 Linux版Redis的下载地址为:https://redis.io/down...

  • redis 生产环境安装

    redis 生产环境安装 linux 安装redis need tcl 8.5 or newer wget htt...

  • 【5】安装redis

    安装 下载Linux安装包,解压 进入redis目录 cd redis 编译redis,直接敲 make 回车 编...

网友评论

      本文标题:linux安装redis

      本文链接:https://www.haomeiwen.com/subject/ulxvwftx.html