Skip to content

Instantly share code, notes, and snippets.

@Muqsit
Last active December 20, 2017 15:23
Show Gist options
  • Save Muqsit/4ac27b5e07432ef3e5ad07c6f58da40f to your computer and use it in GitHub Desktop.
Save Muqsit/4ac27b5e07432ef3e5ad07c6f58da40f to your computer and use it in GitHub Desktop.
Redis PHP get,set
<?php
//This is the redis database being selected
//Databases in redis are integers (0-15) unlike
//mysql where the database can be a string
const REDIS_DATABASE = 0;
$redis = new \Redis();// https://github.com/phpredis/phpredis
$redis->connect("127.0.0.1");
$redis->select(REDIS_DATABASE);
//KEY => VAL(string)
$redis->set("software", "pmmp/PocketMine-MP");
$redis->get("software");//"pmmp/PocketMine-MP"
$redis->get("waresoft");//bool(false)
$redis->delete("software");
$redis->get("software");//bool(false)
//[KEY => VAL(string)]
$redis->hSet("Array1", "key", "value");
$redis->hGet("Array1", "key");//"value"
$redis->hGet("Array1", "key1");//bool(false)
$redis->hSet("Array1", "key1", "1");
$redis->hIncr("Array1", "key1");
$redis->hGet("Array1", "key1");//"2"
$redis->hGetAll("Array1");//["key" => "value", "key1" => "2"]
$redis->hDel("Array1", "key1");
$redis->hGetAll("Array1");//["key" => "value"]
$redis->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment