• redis操作


    1.基本操作

    1.连接redis
    	[root@db01 redis]# redis-cli 
        127.0.0.1:6379>
    2.查看所有数据
        127.0.0.1:6379> keys *
        (empty list or set)
    	#查看时注意不要轻易使用,如想查看数据,先查看数据量DBSIZE
    	127.0.0.1:6379> DBSIZE
    	(integer) 2018041
    3.添加数据
        127.0.0.1:6379> set k1 v1
        OK
    4.查看数据
        127.0.0.1:6379> keys *
        1) "k1"
        127.0.0.1:6379> get k1
        "v1"
    5.删除数据
        127.0.0.1:6379> keys *
        1) "k1"
        127.0.0.1:6379> DEL k1
        (integer) 1
        127.0.0.1:6379> keys *
        (empty list or set)
    6.修改数据
    	127.0.0.1:6379> set k1 v1
        OK
        127.0.0.1:6379> set k1 v11111
        OK
        127.0.0.1:6379> get k1
        "v11111"
    7.追加数据
    	127.0.0.1:6379> APPEND k1 000000
        (integer) 12
        127.0.0.1:6379> get k1
        "v11111000000"
    8.切换库
        127.0.0.1:6379> SELECT 1
        OK
        127.0.0.1:6379[1]> SELECT 2
        OK
        127.0.0.1:6379[2]> SELECT 3
        OK
        127.0.0.1:6379> SELECT 16
        (error) ERR invalid DB index
    

    2.密码的设置

    1.配置文件配置密码
        [root@db01 redis]# vim redis.conf 
        requirepass 123
    2.使用密码连接
    	[root@db01 redis]# redis-cli -a 123
    3.登陆后输入密码
    	[root@db01 redis]# redis-cli
        127.0.0.1:6379> AUTH 123
        OK
        127.0.0.1:6379> DBSIZE
        (integer) 2018041
    4.redis连接后获取密码
        127.0.0.1:6379> CONFIG GET requirepass
        1) "requirepass"
        2) "123"
    5.redis连接后修改密码
        127.0.0.1:6379> CONFIG set requirepass 234
        OK
        [root@db01 redis]# redis-cli
    	127.0.0.1:6379> DBSIZE
        (error) NOAUTH Authentication required.
        127.0.0.1:6379> auth 123
        (error) ERR invalid password
        127.0.0.1:6379> auth 234
        OK
    

    3.通用操作

    1.判断key是否存在
        127.0.0.1:6379> EXISTS k1
        (integer) 1						#存在则返回1
        127.0.0.1:6379> EXISTS k2
        (integer) 0						#不存在则返回0
    2.修改key的名字
    	127.0.0.1:6379> KEYS *
        1) "k1"
        127.0.0.1:6379> RENAME k1 k100
        OK
        127.0.0.1:6379> KEYS *
        1) "k100"
    3.查看数据类型
    	127.0.0.1:6379> TYPE k100
        string
    4.设置生存时间
    	#以秒为单位
        127.0.0.1:6379> EXPIRE qiudao 10
        (integer) 1
        #以毫秒为单位
        127.0.0.1:6379> PEXPIRE k100 10000
    	(integer) 1
    5.查看生存时间
    	127.0.0.1:6379> TTL k100
        (integer) 1					#正整数生存时间倒计时
        127.0.0.1:6379> TTL k100
        (integer) -1				#-1代表没有设置生存时间
        127.0.0.1:6379> TTL k100
        (integer) -2				#代表设置过生存时间已删除,已过期
    6.取消生存时间
    	127.0.0.1:6379> TTL qiudao
        (integer) 93
        127.0.0.1:6379> PERSIST qiudao
        (integer) 1
        127.0.0.1:6379> TTL qiudao
        (integer) -1
    
  • 相关阅读:
    6:python2、python3 的区别及小数据池
    web前端----html表单操作
    web前端----html基础
    mysql数据库----索引原理与慢查询优化
    MySQL数据库----流程控制
    MySQL数据库----IDE工具介绍及数据备份
    MySQL数据库----数据锁
    MySQL数据库----事务处理
    MySQL数据库----事务
    MySQL数据库----函数
  • 原文地址:https://www.cnblogs.com/Applogize/p/13448975.html
Copyright © 2020-2023  润新知