$redis = new Redis(); #实例化redis类
$redis->connect('127.0.0.1'); #连接服务器
$redis->set('key', 'hello '); #调用方法,设置string类型值
$redis->append('key', 'world'); #修改string类型值
echo $redis->get('key'); #获取redis key的值,并输出显示
echo $redis->type('key'); #获取key 的数据类型
echo $redis->echo('will close...');# 输出字符串
$redis->close(); #关闭连接 通过上面的代码,我们基本完成一个简单redis的存取操作。下面罗列一些Redis类的一些属性及方法
a)连接redis server:
connect :连接server
pconnect :长连接
auth :权限验证
select :选择DB
close : 关闭连接
setOption : 设置 client 选项
getOption : 获取client选项
ping : ping redis server
echo : 输出 字符串
Note that if you operate redis frequently, continuous connect and close will consume a lot of performance. At this time, it is recommended to use pconnect to establish a long connection
b) String reading and writing functions
append: Append the value after the value
decr: Decrement the value of a key
incr: increment the value of a key
get: Get a value
set: Set a value
getSet: Set the value and return the old value
mGet: Get values in batches
mSet: Set values in batches
strlen: Get the value length
Note: If you can use batch operations, try to use batch operations to reduce the performance of frequent connections to the redis database
c) hash reading and writing function
hDel: Delete multiple domains
hExists: Determine whether a hash domain exists
hGet: Get the value of hash field
hGetAll: Get all domain values
hIncrBy: auto-increment the value of a hash int field
hKeys: Get hash of all domains
hLen: Get the number of domains
hMGet: Get domain values in batches
hMSet: Set domain values in batches
hSet: Set the value of the field
hVals: Get the values of all fields
d) list reading and writing functions
lInsert: Insert element
lLen: list length
lPop: Remove and get the first color
lPush: Insert an element
lRem: remove element
lSet: Set element value
e)set
sAdd: Add one or more members
sIsMember: Whether to contain
sMembers: Get members
sMove: Move members
sPop: Remove members
sRandMember: Get a random member
sRem: Delete
f)sorted set
zAdd: Add one or more
zCard: Number of members
zIncrBy: Increment member score
zRange: Returns members within the index range
zRangeByScore: Returns members within the score range
zScore: Get member score
zRem: Remove one or more members
http://www.bkjia.com/PHPjc/477640.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477640.htmlTechArticle1. Install php extension a) Install php extension phpredis: [plain] [root@xsf002 tool]# git clone https://github.com/nicolasff/phpredis.git phpredis [root@xsf002 tool]# cd phpredis/ [root@x...