Connect와 기본 keys-and-strings 샘플자료
- <?php
- $redis = new Redis();
- try {
- $redis->connect('127.0.0.1', 6379, 2.5);//2.5 sec timeout
- //Auth Password(redis.conf requirepass)
- //$redis->auth('foobared');
- } catch (Exception $e) {
- exit( "Cannot connect to redis server : ".$e->getMessage() );
- }
- // //DB Select
- if ( !$redis->select(0) ){
- exit( "NOT DB Select");
- }
- $redis->set('key1','value1',10); //유효기간 10초
- echo $redis->get('key1');
- /*
- * print : value1
- */
- ?>
자세한 명령어 사용법은 아래 메뉴얼참조
https://github.com/nicolasff/phpredis#keys-and-strings
Strings
append - Append a value to a key
bitcount - Count set bits in a string
bitop - Perform bitwise operations between strings
decr, decrBy - Decrement the value of a key
get - Get the value of a key
getBit - Returns the bit value at offset in the string value stored at key
getRange - Get a substring of the string stored at a key
getSet - Set the string value of a key and return its old value
incr, incrBy - Increment the value of a key
incrByFloat - Increment the float value of a key by the given amount
mGet, getMultiple - Get the values of all the given keys
mSet, mSetNX - Set multiple keys to multiple values
set - Set the string value of a key
setBit - Sets or clears the bit at offset in the string value stored at key
setex, psetex - Set the value and expiration of a key
setnx - Set the value of a key, only if the key does not exist
setRange - Overwrite part of a string at key starting at the specified offset
strlen - Get the length of the value stored in a key
Keys
del, delete - Delete a key
dump - Return a serialized version of the value stored at the specified key.
exists - Determine if a key exists
expire, setTimeout, pexpire - Set a key's time to live in seconds
expireAt, pexpireAt - Set the expiration for a key as a UNIX timestamp
keys, getKeys - Find all keys matching the given pattern
scan - Scan for keys in the keyspace (Redis >= 2.8.0)
migrate - Atomically transfer a key from a Redis instance to another one
move - Move a key to another database
object - Inspect the internals of Redis objects
persist - Remove the expiration from a key
randomKey - Return a random key from the keyspace
rename, renameKey - Rename a key
renameNx - Rename a key, only if the new key does not exist
type - Determine the type stored at key
sort - Sort the elements in a list, set or sorted set
ttl, pttl - Get the time to live for a key
restore - Create a key using the provided serialized value, previously obtained with dump.