[日常] Redis基本使用测试
|
Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 与范围查询, bitmaps, hyperloglogs 和 地理空间(geospatial) 索引半径查询。 Redis 内置了 复制(replication),LUA脚本(Lua scripting), LRU驱动事件(LRU eviction),事务(transactions) 和不同级别的 磁盘持久化(persistence), 并通过 Redis哨兵(Sentinel)和集群(Cluster)提供高可用性(high availability)。 特点:Redis数据库完全在内存中,使用磁盘仅用于持久性。相比许多键值数据存储,Redis拥有一套较为丰富的数据类型。Redis可以将数据复制到任意数量的从服务器。 命令:测试:ping 返回pong字符串:get set哈希:hmset hget hgetall hmset student name "taoshihan" point 100 hgetall student hget student name列表: lpush lrange lpush users "taoshihan2" lrange users 0 -1集合:元素唯一 sadd smembers sadd people aaa smembers people有序集合:成员有分数 zadd zrangebyscore zadd man 2 aaa zadd man 1 bbb zrangebyscore man 0 1000订阅: subscribe publish subscribe testChat publish testChat "hello world"事务: multi exec multi开启事务,写命令,exec开始执行 php:1.pecl install redis;//安装扩展2.配置php.ini3.php -m|grep redis ;//检测扩展 = ->connect('127.0.0.1',6379->set('name_1','taoshihan'=->get('name_1'(<span style="color: #008000">//<span style="color: #008000">hash<span style="color: #800080">$redis->hMSet("student",<span style="color: #0000ff">array("name"=>"taoshihan","point"=>200<span style="color: #000000">)); <span style="color: #800080">$res=<span style="color: #800080">$redis->hGet("student","point"<span style="color: #000000">); <span style="color: #008080">var_dump(<span style="color: #800080">$res<span style="color: #000000">); <span style="color: #008000">//<span style="color: #008000">list <span style="color: #008000">//<span style="color: #008000">set <span style="color: #008000">//<span style="color: #008000">Sorted sets <span style="color: #008000">//<span style="color: #008000">Pub/sub <span style="color: #008000">//<span style="color: #008000">$redis->subscribe(array('testChat'),'f'); //transactions (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
