【工具库】--redis 安装+使用示例+安全(181)
来源:互联网 发布:linux c 编译器 编辑:程序博客网 时间:2024/06/03 17:52
1 安装
//ubuntu 操作系统
$sudo apt-get update $sudo apt-get install redis-server$redis-server$redis-cli
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379> CONFIG GET *
redis 127.0.0.1:6379> CONFIG SET loglevel “notice”
OK
redis 127.0.0.1:6379> CONFIG GET loglevel
1) “loglevel”
2) “notice”
2 操作数据类型 5种
Redis supports 5 types of data types. strings, hashes, lists, sets and sorted sets
1 strings
redis 127.0.0.1:6379> SET name “tutorialspoint”
OK
redis 127.0.0.1:6379> GET name
“tutorialspoint”
Note − A string value can be at max 512 megabytes in length.
2 hashes:
A Redis hash is a collection of key value pairs. Redis Hashes are maps between string fields and string values. Hence, they are used to represent objects.
redis 127.0.0.1:6379> HMSET user:1 username tutorialspoint password
tutorialspoint points 200
OK
redis 127.0.0.1:6379> HGETALL user:1
1) “username”
2) “tutorialspoint”
3) “password”
4) “tutorialspoint”
5) “points”
6) “200”
Every hash can store up to 2的(32) - 1 field-value pairs (more than 4 billion).
3 lists
Redis Lists are simply lists of strings, sorted by insertion order. You can add elements to a Redis List on the head or on the tail.
redis 127.0.0.1:6379> lpush tutoriallist redis
(integer) 1
redis 127.0.0.1:6379> lpush tutoriallist mongodb
(integer) 2
redis 127.0.0.1:6379> lpush tutoriallist rabitmq
(integer) 3
redis 127.0.0.1:6379> lrange tutoriallist 0 10
1) “rabitmq”
2) “mongodb”
3) “redis”
The max length of a list is 2的(32) - 1 elements (4294967295, more than 4 billion of elements per list).
4 sets
Redis Sets are an unordered collection of strings. In Redis, you can add, remove, and test for the existence of members in O(1) time complexity.
redis 127.0.0.1:6379> sadd tutoriallist redis
(integer) 1
redis 127.0.0.1:6379> sadd tutoriallist mongodb
(integer) 1
redis 127.0.0.1:6379> sadd tutoriallist rabitmq
(integer) 1
redis 127.0.0.1:6379> sadd tutoriallist rabitmq
(integer) 0
redis 127.0.0.1:6379> smembers tutoriallist
1) “rabitmq”
2) “mongodb”
3) “redis”
Note − In the above example, rabitmq is added twice, however due to unique property of the set, it is added only once.
The max number of members in a set is 2的(32) - 1 (4294967295, more than 4 billion of members per set).
5 sorted sets
redis 127.0.0.1:6379> zadd tutoriallist 0 redis
(integer) 1
redis 127.0.0.1:6379> zadd tutoriallist 0 mongodb
(integer) 1
redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq
(integer) 1
redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq
(integer) 0
redis 127.0.0.1:6379> ZRANGEBYSCORE tutoriallist 0 1000
1) “redis”
2) “mongodb”
3) “rabitmq”
3 安全
127.0.0.1:6379> config get requirepass
1) “requirepass”
2) “”
127.0.0.1:6379> config set requirepass “zw”
OK
127.0.0.1:6379> config get requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth zw
OK
127.0.0.1:6379> config get requirepass
1) “requirepass”
2) “zw”
127.0.0.1:6379>
Run Commands on the Remote Server
$ redis-cli -h host -p port -a password
Following example shows how to connect to Redis remote server, running on host 127.0.0.1, port 6379 and has password mypass.
$redis-cli -h 127.0.0.1 -p 6379 -a “mypass”
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG
- 【工具库】--redis 安装+使用示例+安全(181)
- Redis安装和使用示例
- Redis安装和使用示例
- Redis安装和使用示例
- Windows下Redis的安装使用(带Java示例)
- redis安装和安全
- redis可视化工具redis-desktop-manager安装和使用
- Jedis(Redis)使用示例
- Redis使用示例
- linux下redis的安装和使用示例
- Redis之Centos6安装使用及Windows客户端工具(绿色免安装版)下载
- 如何下载和安装、使用xshell(安全终端模拟软件)工具
- Redis 安装与简单示例
- Redis入门(二):linux下安装redis及Jedis使用示例
- Windows 下Redis的安装教程和PHP使用Redis示例
- GDAL工具使用示例(一)
- GDAL工具使用示例(一)
- XDC工具使用示例
- linux设备驱动之hello
- SRM551 Div1Medium ColorfulWolves
- SPEC2000程序编译和性能热点分析
- JAVA实现网页爬虫及将数据写入数据库
- 数据结构快速排序法
- 【工具库】--redis 安装+使用示例+安全(181)
- 类加载机制
- 工程中常用的特征选择方法
- 165_集合_SortedSet集合详解_02_实现Comparable接口
- A + B Problem||
- 冒泡排序
- iOS之使用模拟器报错:resource fork, Finder information, or similar detritus not allowed完美解决方案
- 算法导论 练习题 10.2-7
- Maven安装成功后,总是无法成功mvn install?解决方法是JDK设置的问题。