How to get and set session data in drupal 8

Well you can guess it, it is with services :) so statically calling it would be 

$tempstore = \Drupal::service('tempstore.private')->get('some_namespace');
$tempstore->set('my_variable_name', $some_data);

where some_namespace is the name you choose for it to identify where this data is stored. To retrieve data you do similar but with get 

$tempstore = \Drupal::service('tempstore.private')->get('some_namespace');
$some_data = $tempstore->get('my_variable_name');

There is also other service called tempstore.shared which is used for shared data or as docs says

The PrivateTempStore differs from the SharedTempStore in that all keys are ensured to be unique for a particular user and users can never share data. If you want to be able to share data between users or use it for locking, use \Drupal\user\SharedTempStore.

In the end this is all similar to this, but with levels of abstractions around it.

// Save the data:
$_SESSION['some_namespace']['my_variable_name'] = $somedata;
// Get the data:
$somedata = $_SESSION['some_namespace']['my_variable_name'];

Also note that before 8/2018 this were called user.private_tempstore and user.shared_tempstore but are now deprecated.