首页 > 数据库 >ubuntu安装redis

ubuntu安装redis

时间:2023-09-07 17:55:38浏览次数:46  
标签:127.0 keys 0.1 redis 6379 key ubuntu 安装

sudo apt install redis-server
检查运行状态
sudo systemctl status redis-server
出现以下就是在运行
redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor > Active: activating (start) since Thu 2023-09-07 15:35:19 CST; 9s ago Docs: http://redis.io/documentation, man:redis-server(1) Process: 28954 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=> Tasks: 0 (limit: 18998) Memory: 452.0K CGroup: /system.slice/redis-server.service
启动①redis-server
中文乱码问题
启动Redis服务时,使用 ./redis-cli --raw 命令行。

redis设置值
set key value
多个值
mset key value key value...
设置过期时间
set key value ep(s) ex(s) px(ms)
127.0.0.1:6379> set "pwd" "147055A" ex 60 OK
redis命令行练习
`

./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name "jack"
OK
127.0.0.1:6379> get name
"jack"
127.0.0.1:6379> set sex "男"
OK
127.0.0.1:6379> get sex
"\xe7\x94\xb7"
127.0.0.1:6379>
yp@yp-MS-7D22:/usr/bin$ ./redis-cli --raw
127.0.0.1:6379> get sex

127.0.0.1:6379> set name "jack"
OK
127.0.0.1:6379> get name
jack
127.0.0.1:6379> mset 1 2 3 4
OK
127.0.0.1:6379> get 1
2
127.0.0.1:6379> get 3
4
127.0.0.1:6379> set 11 15 ex 1
OK
127.0.0.1:6379> get 11

127.0.0.1:6379> set "pwd" "147055A" ex 60
OK
127.0.0.1:6379> get pwd
147055A
127.0.0.1:6379> get pwd
147055A
127.0.0.1:6379> keys *
1
pwd
name
3
sex
127.0.0.1:6379> del 1
1
127.0.0.1:6379> keys *
pwd
name
3
sex
127.0.0.1:6379> key pwd
ERR unknown command 'key', with args beginning with: 'pwd'

127.0.0.1:6379> EXISTS 3
1
127.0.0.1:6379> RANDOMKEY
sex
127.0.0.1:6379> RANDOMKEY
sex
127.0.0.1:6379> RANDOMKEY
sex
127.0.0.1:6379> rename sex
ERR wrong number of arguments for 'rename' command

127.0.0.1:6379> rename sex sex
OK
127.0.0.1:6379> incr 1
1
127.0.0.1:6379> incr 1
2
127.0.0.1:6379> incr 1
3
127.0.0.1:6379> get 1
3
127.0.0.1:6379> get 1
3
127.0.0.1:6379> REnamex sex sexx
ERR unknown command 'REnamex', with args beginning with: 'sex' 'sexx'

127.0.0.1:6379> renamex sex sexx
ERR unknown command 'renamex', with args beginning with: 'sex' 'sexx'

127.0.0.1:6379> INCR 1
4
127.0.0.1:6379> DECR 1
3
127.0.0.1:6379> DECR 1
2
127.0.0.1:6379> TYPE 1
string
127.0.0.1:6379> TYPE 2
none
127.0.0.1:6379> TYPE 3
string
127.0.0.1:6379> TYPE 4
none
127.0.0.1:6379> TYPE 5
none
127.0.0.1:6379> TYPE 11
none
127.0.0.1:6379> HSET demo 1 2
1
127.0.0.1:6379> get demo
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> HSET demo 3 4
1
127.0.0.1:6379> HGET demo
ERR wrong number of arguments for 'hget' command

127.0.0.1:6379> HGET demo 3
4
127.0.0.1:6379> HGET demo 1
2
127.0.0.1:6379> HSET demo "xx" "xxc"
1
127.0.0.1:6379> Hset lu 1 2 3 4 5 6 7 8
4
127.0.0.1:6379> HGETALL lu
1
2
3
4
5
6
7
8
127.0.0.1:6379> Hset wang eat set swimming running skill kill fight
ERR wrong number of arguments for 'hset' command

127.0.0.1:6379> Hset wang eat set swimming running
2
127.0.0.1:6379> Hgetall wang
eat
set
swimming
running
127.0.0.1:6379> HEXISTS eat
ERR wrong number of arguments for 'hexists' command

127.0.0.1:6379> HEXISTS wang eat
1
127.0.0.1:6379> HEXISTS wang eats
0
127.0.0.1:6379> hvalues
ERR unknown command 'hvalues', with args beginning with:

127.0.0.1:6379> hvals wang
set
running
127.0.0.1:6379> hvals lu
2
4
6
8
127.0.0.1:6379> hset lu 23 4 5 6 78 9 89
ERR wrong number of arguments for 'hset' command

127.0.0.1:6379> hset lu 23 4 5 6 78
ERR wrong number of arguments for 'hset' command

127.0.0.1:6379> hset lu 23 4 5 6
1
127.0.0.1:6379> hvals lu
2
4
6
8
4
127.0.0.1:6379> hlen lu
5
127.0.0.1:6379> hlen wang
2
127.0.0.1:6379> LPUSH demo wo ai ni xiaowang
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> LPUSH demo wo ai ni xiaowang
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> LPUSH demo wo ai ni
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> LPUSH demo wo ai ni
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> LPUSH 1 wo ai niya ua
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> LPUSH c wo ai ni
3
127.0.0.1:6379> LPUSH c wo ai ni ya
7
127.0.0.1:6379> LRANGE c 0 -1
ya
ni
ai
wo
ni
ai
wo
127.0.0.1:6379> linsert wo before xx
ERR wrong number of arguments for 'linsert' command

127.0.0.1:6379> linsert ni before wo xx
0
127.0.0.1:6379> linsert ni before ya xx
0
127.0.0.1:6379> LRANGE c 0 -1
ya
ni
ai
wo
ni
ai
wo
127.0.0.1:6379> linsert c before ya xx
8
127.0.0.1:6379> linsert c before ya yy
9
127.0.0.1:6379> linsert c after ya yy
10
127.0.0.1:6379> LRANGE c 0 -1
xx
yy
ya
yy
ni
ai
wo
ni
ai
wo
127.0.0.1:6379> RPOPLPUSH
ERR wrong number of arguments for 'rpoplpush' command

127.0.0.1:6379> lindex c 0
xx
127.0.0.1:6379> lindex c 1
yy
127.0.0.1:6379> lindex c 2
ya
127.0.0.1:6379> lindex c 9
wo
127.0.0.1:6379> lindex c 8
ai
127.0.0.1:6379> sadd key 111 222 333 111 222
3
127.0.0.1:6379> sadd key 111 222 333 111 3232 344
2
127.0.0.1:6379> sadd key 222 222 333 111 3232 344
0
127.0.0.1:6379> scard key
5
127.0.0.1:6379> sadd keys 1234 1235 12465 14556
4
127.0.0.1:6379> scard keys
4
127.0.0.1:6379> SISMEMBER keys 111
0
127.0.0.1:6379> SISMEMBER keys 123
0
127.0.0.1:6379> SISMEMBER keys 124
0
127.0.0.1:6379> SISMEMBER keys 1234
1
127.0.0.1:6379> SMEMBERS key
111
222
333
344
3232
127.0.0.1:6379> SMEMBERS keys
1234
1235
12465
14556
127.0.0.1:6379> SDIFF keys key
1234
1235
12465
14556
127.0.0.1:6379> SINTER keys key

127.0.0.1:6379> SUNION keys key
111
222
333
344
1234
1235
3232
12465
14556
127.0.0.1:6379> smove key keys
ERR wrong number of arguments for 'smove' command

127.0.0.1:6379> smove key 1235 keys
0
127.0.0.1:6379> SPOP keys
12465
127.0.0.1:6379> SPOP keys
14556
127.0.0.1:6379> SREM keys 1234
1
127.0.0.1:6379> ZCARD keys
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> ZCARD key
WRONGTYPE Operation against a key holding the wrong kind of value

127.0.0.1:6379> ZRANGE key start stop
ERR value is not an integer or out of range

127.0.0.1:6379> ZRANGE keys start stop
ERR value is not an integer or out of range

127.0.0.1:6379> save
OK
127.0.0.1:6379> SHUTDOWN
not connected> ./redis-cli

`
springboot 整合 redis
package com.hidisp;

import com.hidisp.entity.User;
import com.hidisp.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
@MapperScan("com.hidisp.mapper")
//如果注入失败 说明没有扫到这个包
class HidispApplicationTests {
@Resource
private UserMapper mapper;

@Resource
RedisTemplate redisTemplate;
Logger logger = LoggerFactory.getLogger(HidispApplicationTests.class);

@Test
void contextLoads() {
    List<User> list = mapper.selectList(null);
    list.forEach(System.out::println);
    logger.info("用户列表被打印出来了。。。");
}

@Test
void context(){
    User user = new User();
    user.setUid(19);
    user.setUname("jadgfgcksongd");
    user.setUpwd("password");
    user.setBirthday("2017-07-01");
    user.setSex("male");
    user.setMarry(1);
    Integer one = mapper.insert(user);
    logger.info("insert successful"+one+"条数据...!");
    mapper.selectList(null).forEach(System.out::println);

}

@Test
void testRedis(){
     redisTemplate.opsForValue().set("a", "b");  //b
    // redisTemplate.opsForHash().put("a", "b","c");
    // redisTemplate.opsForSet().add("a", "b", "c","s", "sd");
    // redisTemplate.opsForList().leftPush("b", "dsd");
    // redisTemplate.opsForList().rightPush("b", "dsds");
}

}

`

标签:127.0,keys,0.1,redis,6379,key,ubuntu,安装
From: https://www.cnblogs.com/chuangchuang/p/17685692.html

相关文章

  • 认识Shell脚本(Ubuntu)
    一:概述  系统管理员在管理主机时需要手动处理所有的工作,Shell脚本就可以让系统自动工作,Shell脚本不需要编译,可以直接执行,功能非常强大,可以帮助我们自动处理很多的工作,简化日常化管理。二:初步了解Shell脚本  在Linux的内部,很多的服务都是基于以Shell脚本(ShellScript)的形式提......
  • redis
    1.Redis是单线程的redis是基于内存操作的,CPU不是操作瓶颈,redis的瓶颈是根据机器内存和网络宽带,那既然CPU不是瓶颈,那就意味着可以用单线程来实现,那就用单线程了!Redis是C语言写的,官方提供的十万QPSredis为什么单线程就快?1.误区:高性能的服务器一定是多线程的,多线程一定比......
  • Redis复习:(1)RedisTempalte之BitMap操作
    packagecn.edu.tju.service.impl;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.dao.DataAccessException;importorg.springframework.data.redis.connection.RedisConnection;importorg.springframework.data.redis.co......
  • Python预安装包制作
    预编译安装包在Linux服务器上,经常会安装Python、Redis、Nginx等服务,不管离线、在线都需要编译、编译之前还需要安装一些依赖的环境,比如,openssl、gcc、g++等,但是make编译的时间过于长,严重影响心情,希望制作一个符合当前系统的预先编译好的包,可以拿来即用的。编译Python3.9.8在......
  • 云服务器——安装Maven
    1.首先新建一个maven文件夹用于下载maven安装包,可采用直接官网下载压缩包上传至服务器,也可以采用wget直接下载,这里采用wget下载wgethttps://archive.apache.org/dist/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz2.下载完之后解压缩tar-zxvfapache-maven-3.......
  • 使用VMware创建虚拟机关于VMware Tools无法安装的问题
    VM版本:操作系统版本:WindowsServer2008R2x641、虚拟机菜单下的安装VMwareTools为灰色解决方案:在虚拟机设置中,找到CD/DVD,选择使用ISO映像文件,找到VMware安装路径下的windows.iso(linux系统选择linux.iso)设置好后,在虚拟机中的光盘中就可以已找到安装程序了,双击安装即可:......
  • VMware vCenter Server 7.0.3 安装
    VMwarevCenterServer7.0.3安装文章目录VMwarevCenterServer7.0.3安装1.安装vcenter1.1第一阶段1.2第二阶段2.exsi查看vcenter3.部署DNSserver3.1安装unbound3.2配置unbound3.3vcenter配置域名访问部署完EXSI7.0.3,你要在EXSI创建一台windows10虚拟机,在......
  • 【ROS2机器人入门到实战】Micro-ROS介绍与服务安装
    1.Micro-ROS介绍与服务安装写在前面当前平台文章汇总地址:ROS2机器人从入门到实战获取完整教程及配套资料代码,请关注公众号<鱼香ROS>获取教程配套机器人开发平台:两驱版|四驱版为方便交流,搭建了机器人技术问答社区:地址fishros.org.cn你好,我是爱吃鱼香ROS的小鱼。本节我们主要介绍下......
  • docker下的php7.3容器安装gd库
    我的docker版本,24.0.5 我的php版本,php7.3.33题外话,之前我们单独安装php-fpm服务的时候,需要装扩展,是直接在服务器上操作的,那么现在php在docker里面了,我们应该怎么来执行安装操作呢1、进入php容器dockerexec-it1e36f97ab14c/bin/bash//1e36f97ab14c为我的php容器的ID......
  • 如何修改Ubuntu的时间与时间同步
    1、安装ntpdate,同步标准时间zce@ubuntu:~$sudoaptinstallntpdate   输入管理员密码确认安装zce@ubuntu:~$sudoaptinstallntpdate[sudo]zce的密码:正在读取软件包列表...完成正在分析软件包的依赖关系树正在读取状态信息...完成ntpdate......